• PHP Video Tutorials

PHP - is_object() Function



Definition and Usage

The function is_object() verifies whether a variable is an object.

Syntax

bool is_object ( mixed $value )

Parameters

Sr.No Parameter Description
1

value

The variable being evaluated.

Return Values

This function returns true if value is a number or a numeric string, false otherwise. Since PHP 7.2: This function now returns true for unserialized objects without a class definition. Earlier false was returned

Dependencies

PHP 4 and above.

Example

Following example demonstrates return values with different types of variables:

<?php
  // Create a class
  class tutorialsPoint {
      public $tp_name =
            "Welcome to TutorialsPoint";
  }

  // Create the class name alias
  class_alias('tutorialsPoint', 'TP');

  $obj1 = new tutorialsPoint();
  $obj2 = new TP();
  $obj3 = 'TutorialsPoint';

  var_dump(is_object($obj1));
  var_dump(is_object($obj2));
  var_dump(is_object($obj3));
?>

Output

This will produce following result −

bool(true)
bool(true)
bool(false)
Advertisements