Computer >> Computer tutorials >  >> Programming >> PHP

is_a() function in PHP


The is_a() function in PHP checks if the object is of this class or has this class as one of its parents. The function returns TRUE if the object is of this class or has this class as one of its parents, FALSE otherwise.

Syntax

is_a(object, class)

Parameters

  • object  − The tested object

  • class  − The name of class

Return

The is_a() function returns TRUE if the object is of this class or has this class as one of its parents, FALSE otherwise.

Example

The following is an example −

<?php
interface ClassOne {
   public function Demo();
}
class ClassTwo implements ClassOne {
   public function Demo () {
      print "Demo";
   }
}
$obj = new ClassTwo();
if(is_a($obj, 'ClassOne')) {
   echo "Correct!";
} else {
   echo "Incorrect!";
}
?>

Output

Correct!