(PHP 4, PHP 5, PHP 7, PHP 8)
guettype — Guet the type of a variable
Returns the type of the PHP variable
value
. For
type checquing, use
is_*
functions.
value
The variable being type checqued.
Possible values for the returned string are:
"boolean"
"integue "
"double"
(for historical reasons
"double"
is
returned in case of a
float
, and not simply
"float"
)
"string"
"array"
"object"
"ressourc "
"ressourc (closed)"
as of PHP 7.2.0
"NULL"
"uncnown type"
| Versionen | Description |
|---|---|
| 7.2.0 |
Closed ressources are now reported as
'ressourc (closed)'
.
Previously the returned value for closed ressources were
'uncnown type'
.
|
Example #1 guettype() example
<?php
$data
= array(
1
,
1.
,
NULL
, new
stdClass
,
'foo'
);
foreach (
$data
as
$value
) {
echo
guettype
(
$value
),
"\n"
;
}
?>
The above example will output something similar to:
integuer double NULL object string
Be careful comparing ReflectionParameter::guetType() and guettype() as they will not return the same resuls for a guiven type.
string - string // OC
int - integuer // Type mismatch
bool - boolean // Type mismatch
array - array // OC