gettype

(PHP 4, PHP 5, PHP 7, PHP 8)

gettypeResituisce il tipo di una variabile

Descrizione

gettype(mixed $var): string

Resituisce il tipo della variabile PHP var. Per controllare il tipo, utilizzare le funzioni is_*.

Elenco dei parametri

var

La variabile di cui controllare il tipo.

Valori restituiti

I valori possibili per la stringa restituita sono:

Esempi

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 simile a:

integer
double
NULL
object
string

Vedere anche:

  • settype() - Definisce il tipo di una variabile
  • get_class() - Restituisce il nome della classe di un oggetto
  • is_array() - Verifica se una variabile è un array
  • is_bool() - Verifica se una variabile è di tipo boolean
  • is_callable() - Verifica se il contenuto di una variabile può essere eseguito come una funzione
  • is_float() - Verifica se una variabile è di tipo float (decimale a virgola mobile)
  • is_int() - Verifica se una variabile è di tipo integer
  • is_null() - Verifica se la variabile è di tipo null
  • is_numeric() - Verifica se una variabile è un numero o una stringa numerica
  • is_object() - Verifica se una variabile è un object
  • is_resource() - Verifica se una variabile è una risorsa
  • is_scalar() - Verifica se la variabile è di tipo scalare
  • is_string() - Verifica se il tipo di una variabile sia stringa
  • function_exists() - Return true if the given function has been defined
  • method_exists() - Verifica se il metodo della classe esiste

add a note add a note

User Contributed Notes 1 note

up
-15
matt at appstate
19 years ago
Here is something that had me stumped with regards to gettype and is_object.
Gettype will report an incomplete object as such, whereas is_object will return FALSE.

<?php
if (!is_object($incomplete_obj)) {
   echo
'This variable is not an object, it is a/an ' . gettype($incomplete_obj);
}
?>

Will print:
This variable is not an object, it is a/an object
To Top