is_object
(PHP 4, PHP 5)
is_object — Finds whether a variable is an object
Parameters
-
var
-
The variable being evaluated.
Return Values
Returns TRUE
if var
is an object,
FALSE
otherwise.
Examples
Example #1 is_object() example
<?php
// Declare a simple function to return an
// array from our object
function get_students($obj)
{
if (!is_object($obj)) {
return false;
}
return $obj->students;
}
// Declare a new class instance and fill up
// some values
$obj = new stdClass();
$obj->students = array('Kalle', 'Ross', 'Felipe');
var_dump(get_students(null));
var_dump(get_students($obj));
?>
Notes
Note:
This function will return
FALSE
if used on an unserialized object where the class definition is not present (even though gettype() returns object).
See Also
- is_bool() - Finds out whether a variable is a boolean
- is_int() - Find whether the type of a variable is integer
- is_float() - Finds whether the type of a variable is float
- is_string() - Find whether the type of a variable is string
- is_array() - Finds whether a variable is an array
- PHP Руководство
- Функции по категориям
- Индекс функций
- Справочник функций
- Расширения, относящиеся к переменным и типам
- Функции для работы с переменными
- boolval
- debug_zval_dump
- doubleval
- empty
- floatval
- get_defined_vars
- get_resource_type
- gettype
- import_request_variables
- intval
- is_array
- is_bool
- is_callable
- is_double
- is_float
- is_int
- is_integer
- is_long
- is_null
- is_numeric
- is_object
- is_real
- is_resource
- is_scalar
- is_string
- isset
- print_r
- serialize
- settype
- strval
- unserialize
- unset
- var_dump
- var_export
Коментарии
Note: is_object(null) returns false
This should actually be part of the input/output specification at the top of this page.
Unserializes data as returned by the standard PHP serialize() function. If the unserialized object is not an array, it will be converted to one, particularily useful if it returns a __PHP_Incomplete_Class.
<?php
/**
*
* @param string $data Serialized data
*
* @return array Unserialized array
*/
function unserialize2array($data) {
$obj = unserialize($data);
if(is_array($obj)) return $obj;
$arr = array();
foreach($obj as $k=>$v) {
$arr[$k] = $v;
}
unset($arr['__PHP_Incomplete_Class_Name']);
return $arr;
}
?>
I would expect a reference to is_a() function here.
if you would test if an object is of an specific type use is_a()
https://www.php.net/manual/en/function.is-a.php