gettype

(PHP 4, PHP 5)

gettypeGet the type of a variable

Description

string gettype ( mixed $var )

Returns the type of the PHP variable var. For type checking, use is_* functions.

Parameters

var

The variable being type checked.

Return Values

Possible values for the returned string are:

Examples

Example #1 gettype() example

<?php

$data 
= array(11.NULL, new stdClass'foo');

foreach (
$data as $value) {
    echo 
gettype($value), "\n";
}

?>

The above example will output something similar to:

integer
double
NULL
object
string

See Also

Коментарии

Автор:
Same as for "boolean" below, happens with integers. gettype() return "integer" yet proper type hint is "int". 

If your project is PHP8+ then you should consider using get_debug_type() instead which seems to return proper types that match used for type hints.
2022-01-20 20:59:34
http://php5.kiev.ua/manual/ru/function.gettype.html
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
2023-06-11 15:37:35
http://php5.kiev.ua/manual/ru/function.gettype.html

    Поддержать сайт на родительском проекте КГБ