❮ PHP Variable Handling Reference
Check whether a variable is an object or not:
<?php
function get_cars($obj) {
if (!is_object($obj)) {
return false;
}
return $obj->cars;
}
$obj = new stdClass();
$obj->cars = array("Volvo", "BMW", "Audi");
var_dump(get_cars(null));
echo "<br>";
var_dump(get_cars($obj));
?>
Try it Yourself »
The is_object() function checks whether a variable is an object.
This function returns true (1) if the variable is an object, otherwise it returns false/nothing.
is_object(
variable);
Parameter | Description |
---|---|
variable | Required. Specifies the variable to check |
Return Value: | TRUE if variable is an object, FALSE otherwise |
---|---|
Return Type: | Boolean |
PHP Version: | 4.0+ |
PHP Changelog: | PHP 7.2: This function now returns true for unserialized objects without a class definition. Earlier false was returned |
截取页面反馈部分,让我们更快修复内容!也可以直接跳过填写反馈内容!