is_a
Description
The is_a of Class / Object for PHP checks if the object is of this class or has this class as one of its parents.
Syntax
is_a( mixed $object_or_class, string $class, bool $allow_string = false ): bool
Parameters
object_or_class
A class name or an object instance.
class
The class or interface name.
allow_string
If this parameter set to false, string class name as object_or_class is not allowed. This also prevents from calling autoloader if the class doesn't exist.
Return
Returns true if object_or_class is the class object type, or has class as one of its supertypes, false otherwise.
Examples
1 · object_or_class class
<? class myclass { } $object_or_class = new myclass(); $class = "myclass"; $return = is_a($object_or_class, $class); var_export($return); ?>
true
2 · allow_string · false
<? class myclass { } $object_or_class = "myclass"; $class = "myclass"; $allow_string = false; $return = is_a($object_or_class, $class, $allow_string); var_export($return); ?>
false
3 · allow_string · true
<? class myclass { } $object_or_class = "myclass"; $class = "myclass"; $allow_string = true; $return = is_a($object_or_class, $class, $allow_string); var_export($return); ?>
true
4 · namespace
<? namespace mynamespace; class myclass { } $object_or_class = new myclass(); $class = "mynamespace\myclass"; $return = is_a($object_or_class, $class); var_export($return); ?>
true
5 · instanceof
<? class myclass { } $object_or_class = new myclass(); if($object_or_class instanceof myclass) { echo "true"; } else { echo "false"; } ?>
true