Be careful comparing ReflectionParameter::getType() and gettype() as they will not return the same results for a given type.
string - string // OK
int - integer // Type mismatch
bool - boolean // Type mismatch
array - array // OK(PHP 4, PHP 5, PHP 7, PHP 8)
gettype — Devuelve el tipo de la variable
Devuelve el tipo de la variable value.
Para verificar el tipo de la variable, se pueden
utilizar las funciones is_*.
valueLa variable a analizar.
Las cadenas de caracteres que puede devolver la función son las siguientes:
"boolean"
"integer"
"double" (por razones históricas,
"double" es devuelto cuando un valor de tipo
float es proporcionado, y no "float")
"string"
"array"
"object"
"resource"
"resource (closed)" a partir de PHP 7.2.0
"NULL"
"unknown type"
| Versión | Descripción |
|---|---|
| 7.2.0 |
Los recursos cerrados son ahora reportados como 'resource (closed)'.
Anteriormente, el valor devuelto para recursos cerrados era 'unknown type'.
|
Ejemplo #1 Ejemplo con gettype()
<?php
$data = array(1, 1., NULL, new stdClass, 'foo');
foreach ($data as $value) {
echo gettype($value), "\n";
}
?>Resultado del ejemplo anterior es similar a:
integer double NULL object string
Be careful comparing ReflectionParameter::getType() and gettype() as they will not return the same results for a given type.
string - string // OK
int - integer // Type mismatch
bool - boolean // Type mismatch
array - array // OK