is_subclass_of

FunctionParams and return types changed in PHP 8.0

Checks if the object has this class as one of its parents or implements it.

PHP 5
PHP 7
PHP 8.0
Improved
PHP 8.1
PHP 8.2
PHP 8.3
PHP 8.4
PHP 8.5

is_subclass_of Function synopsis

is_subclass_of(
    mixed $object_or_class,
    string $class,
    bool $allow_string = true
  ): bool

Parameters

$object_or_class

Typemixed

A class name or an object instance. No error is generated if the class does not exist.

$class

Typestring

The class name

$allow_string

OptionalTypeboolDefault valuetrue

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 value

Typebool

This function returns true if the object $object_or_class, belongs to a class which is a subclass of $class, false otherwise.

Changes to the is_subclass_of Function

PHP 8.0

  • Return type added: bool
  • Parameter name of parameter #1 changed: $object to $object_or_class
  • Parameter type added for parameter #1 ($object_or_class): mixed
  • Parameter name of parameter #2 changed: $class_name to $class
  • Parameter type added for parameter #2 ($class): string
  • Parameter type added for parameter #3 ($allow_string): bool
  • Parameter default value added for position #3 ($allow_string): true
  is_subclass_of(
-     $object,
+     mixed $object_or_class,
-     $class_name,
+     string $class,
-     $allow_string
+     bool $allow_string = true
-   )
+   ): bool

PHP 5.4

  • Optional parameter added - #3: $allow_string
-is_subclass_of($object, $class_name)
+is_subclass_of(
+    $object,
+    $class_name,
+    $allow_string
+  )

is_subclass_of Function Availability

PHP VersionAvailability
PHP 8.5Future Release Yes
PHP 8.4Upcoming Release Yes
PHP 8.3Supported (Latest) Yes
PHP 8.2Supported Yes
PHP 8.1Security-Fixes Only Yes
PHP 8.0Unsupported Yes
PHP 7.4Unsupported Yes
PHP 7.3Unsupported Yes
PHP 7.2Unsupported Yes
PHP 7.1Unsupported Yes
PHP 7.0Unsupported Yes
PHP 5.6Unsupported Yes
PHP 5.5Unsupported Yes
PHP 5.4Unsupported Yes
PHP 5.3Unsupported Yes