The is_a Function

The is_a function takes an object and a class name, returning true if the object is an instance of that class or its descendant. The third parameter can specify whether to consider inheritance (default is true).

Syntax

phpis_a(object, class_name, allow_string = true);

Example

Let's check if the object belongs to the stdClass class:

php<?php
  $obj = new stdClass();
  var_dump(is_a($obj, 'stdClass'));
?>

Code execution result:

phptrue

Example

Let's check class inheritance:

php<?php
  class ParentClass {}
  class ChildClass extends ParentClass {}
  
  $child = new ChildClass();
  var_dump(is_a($child, 'ParentClass'));
?>

Code execution result:

phptrue

Example

Let's check the work with interfaces:

php<?php
  interface MyInterface {}
  class MyClass implements MyInterface {}
  
  $obj = new MyClass();
  var_dump(is_a($obj, 'MyInterface'));
?>

Code execution result:

phptrue

See Also