PHP is_object() Function

P
PHP output_reset_rewrite_vars() Function
php foreach() keyword

In this article, you will learn how to check if a variable is an object of not. In PHP the is_object() function checks if a variable is an object. This function returns true (1) if the variable is an object, otherwise it returns false/nothing.

what is the syntax of the IS_OBJECT() function in php?

is_object(variable);
ParametersDetails
variableRequired – Specifies the variable to check
PHP IS_OBJECT() method

examples of the IS_OBJECT() function

Example 1. In this example, we 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));
?>
PHP output_reset_rewrite_vars() Function
php foreach() keyword

Add comment

Tutor Network

Share this

Learn PHP from A to Z