Current Location: Home> Function Categories> is_object

is_object

Detect whether a variable is an object
Name:is_object
Category:Variable processing
Programming Language:php
One-line Description:Check whether the variable is an object.

Definition and usage

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.

Example

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

grammar

 is_object ( variable ) ;
parameter describe
variable Required. Specifies the variable to check.
Similar Functions
Popular Articles