is_a()
is_a() — Checks whether the object is of a given type or subtype.
Built-in function of PHP 8.5. The manual lists it as available in PHP 4 >= 4.2.0, PHP 5, PHP 7, PHP 8. This page is the reference card: signature, parameters and return value, plus the changelog and the example the manual provides.
What it does
Determines if the given object_or_class is the class object type, or has class as one of its supertypes.
Signature
is_a(mixed $object_or_class, string $class, bool $allow_string = false): bool
Parameters
| Parameter | Type | What it takes |
|---|---|---|
| $object_or_class | mixed | A class name or an object instance. |
| $class | string | The class or interface name |
| $allow_string | bool | If this parameter is set to false, a string class name as object_or_class is not allowed. This also prevents calling the autoloader if the class doesn't exist. |
Return value
Returns true if object_or_class is the class object type, or has class as one of its supertypes, false otherwise.
Example
A runnable snippet:
// define a class class WidgetFactory { var $oink = 'moo'; } // create a new object $WF = new WidgetFactory(); if (is_a($WF, 'WidgetFactory')) { echo "yes, \$WF is still a WidgetFactory\n"; }
See also
get_class(), get_parent_class(), is_subclass_of()
All PHP 8.5 built-in functions
Reference card built from the PHP manual page is_a() (PHP documentation, CC BY 3.0). The page is generated from the manual, so the wording of the parameter and return value text follows php.net.