The is_object Function

The is_object function checks whether the passed variable is an object. Returns true if the variable is an object, and false otherwise. Accepts the variable to be checked as a parameter.

Syntax

phpis_object(mixed $value): bool

Example

Let's check if the variable is an object:

php<?php
  $obj = new stdClass();
  $res = is_object($obj);
  var_dump($res);
?>

Code execution result:

phptrue

Example

Let's check other data types:

php<?php
  $arr = [1, 2, 3];
  $str = 'test';
  var_dump(is_object($arr));
  var_dump(is_object($str));
?>

Code execution result:

phpfalse
false

See Also

  • the is_array function,
    which checks whether a variable is an array
  • the is_string function,
    which checks whether a variable is a string