30 of 410 menu

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

is_object(mixed $value): bool

Example

Let's check if the variable is an object:

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

Code execution result:

true

Example

Let's check other data types:

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

Code execution result:

false 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
byenru