gettype

(PHP 3, PHP 4, PHP 5)

gettype -- Get the type of a variable

Description

string gettype ( mixed var )

Returns the type of the PHP variable var.

Внимание

Never use gettype() to test for a certain type, since the returned string may be subject to change in a future version. In addition, it is slow too, as it involves string comparison.

Instead, use the is_* functions.

Possibles values for the returned string are:

For PHP 4, you should use function_exists() and method_exists() to replace the prior usage of gettype() on a function.

See also settype(), is_array(), is_bool(), is_float(), is_int(), is_null(), is_numeric(), is_object(), is_resource(), is_scalar(), and is_string().



gettype
gilthansNOSPAM at gmail dot com
11-Sep-2005 01:18
NaN and #IND will return double or float on gettype, while some inexistent values, like division by zero, will return as a boolean FALSE. 0 by the 0th potency returns 1, even though it is mathematically indetermined.

<?php
$number
= 5/0;
$number2 = sqrt(-3);
$number3 = pow(0, 0);
$number4 = 0/0;

echo
$number."<br />";
echo
$number2."<br />";
echo
$number3."<br />";
echo
$number4."<br />";
echo
"<br />";
echo
gettype($number)."<br />";
echo
gettype($number2)."<br />";
echo
gettype($number3)."<br />";
echo
gettype($number4);
?>

This will return:

-1.#IND
1

boolean
double
integer
boolean

0
1
1
0
PHP Warning: Division by zero in C\test.php on line 2 PHP Warning: Division by zero in C:\test.php on line 5
matt at appstate
16-Dec-2004 11:10
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.

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
jose at vocis dot com
14-Sep-2000 09:22
Also returns "NULL" for variables assigned the return of a function that returned no value via "return;".

<code>

function weird(){
   return;
}
$a=weird();

</code>

isset($a) <> 1
empty($a) <> 1
gettype($a) == NULL

-Jose Batista
ojones at dotclick dot com
31-Aug-2000 10:19
After calling OCIResult to retrieve a NULL result from an Oracle result-set, gettype returns the string 'NULL'.

<get_resource_typeimport_request_variables>
 Last updated: Tue, 15 Nov 2005