is_object
Detect whether a variable is an object
is_object()
function checks whether the variable is an object.
If the variable is an object, the function returns true
(1), otherwise false
/ no return value.
Check whether the variable is an object:
<?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
is_object ( variable ) ;
parameter | describe |
---|---|
variable | Required. Specifies the variable to check. |