Forum und email

gettype

(PHP 4, PHP 5)

gettype — Resituisce il tipo di una variabile

Descrizione

string gettype ( mixed $var )

Restituisce il tipo della variabile PHP var .

Avviso

Non utilizzare gettype() per testare certi tipi di variabili poichè la stringa restistuita potrebbe variare nelle versioni future. Inoltre questa funzione è lenta dato che richiede confronti tra stringhe

Piuttosto utilizzare le funzioni is_*.

La stringa restituita può assumere i seguenti valori:

  • "boolean" (dalla versione 4 di PHP)
  • "integer"
  • "double" (per ragioni storiche viene restituito "double" in caso di variabile di tipo float, e non semplicemente "float")
  • "string"
  • "array"
  • "object"
  • "resource" (dalla versione 4 di PHP)
  • "NULL" (dalla versione 4 di PHP)
  • "user function" (soltanto in PHP 3, deprecated)
  • "unknown type"

Nella versione 4 di PHP si dovrebbe applicare alle funzioni function_exists() o method_exists() al posto del precedente gettype().

Vedere anche settype(), is_array(), is_bool(), is_float(), is_int(), is_null(), is_numeric(), is_object(), is_resource(), is_scalar() e is_string().