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 — Restituisce il tipo di una variabile
Restituisce il tipo della variabile PHP value. Per
controllare il tipo, utilizzare le funzioni is_*.
valueLa variabile di cui controllare il tipo.
I valori possibili per la stringa restituita sono:
"boolean"
"integer"
"double" (per ragioni storiche viene restituito
"double" nel caso di un float, e non semplicemente
"float")
"string"
"array"
"object"
"resource"
"resource (closed)" a partire da PHP 7.2.0
"NULL"
"unknown type"
| Versione | Descrizione |
|---|---|
| 7.2.0 |
Le risorse chiuse vengono ora restituite come 'resource (closed)'.
In precedenza il valore restituito per le risorse chiuse era 'unknown type'.
|
Example #1 Esempio di gettype()
<?php
$data = array(1, 1., NULL, new stdClass, 'foo');
foreach ($data as $value) {
echo gettype($value), "\n";
}
?>Il precedente esempio visualizzerà qualcosa di simile 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