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));
?>
by გიორგი ბაკაშვილი
4 years ago
PHP
Variable Handling
PHP official doc
1
Pro tip: use ```triple backticks around text``` to write in code fences