is_object
(PHP 4, PHP 5, PHP 7, PHP 8)
is_object — 检测变量是否是对象
参数
value
-
需要检测的变量。
示例
示例 #1 is_object() 示例
<?php
// 声明简单的函数,从对象中返回数组
function get_students($obj)
{
if (!is_object($obj)) {
return false;
}
return $obj->students;
}
// 声明新的类实例并填充值
$obj = new stdClass();
$obj->students = array('Kalle', 'Ross', 'Felipe');
var_dump(get_students(null));
var_dump(get_students($obj));
?>
参见
- is_bool() - 检测变量是否是布尔值
- is_int() - 检测变量是否是整数
- is_float() - 检测变量是否是浮点型
- is_string() - 检测变量的类型是否是字符串
- is_array() - 检测变量是否是数组
+添加备注
用户贡献的备注 3 notes
peter dot nagel at portavita dot nl ¶
13 years ago
Note: is_object(null) returns false
This should actually be part of the input/output specification at the top of this page.
mark at not4you dot com ¶
13 years ago
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;
}
?>
monique at nijboer dot it ¶
5 months ago
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