The class_implements Function
The class_implements
function returns an array of interface names
that are implemented by the specified class or interface. The first parameter
takes an object or class name as a string, and the second optional
parameter determines whether autoloading should be used.
Syntax
class_implements(
object|string $class,
[bool $autoload = true]
): array|false
Example
Let's get interfaces for the built-in Exception
class:
<?php
$res = class_implements('Exception');
print_r($res);
?>
Code execution result:
['Throwable']
Example
Let's create a custom interface and class, then check the implemented interfaces:
<?php
interface MyInterface {}
class MyClass implements MyInterface {}
$res = class_implements('MyClass');
print_r($res);
?>
Code execution result:
['MyInterface']
Example
Let's check interfaces for the interface itself:
<?php
interface ParentInterface {}
interface ChildInterface extends ParentInterface {}
$res = class_implements('ChildInterface');
print_r($res);
?>
Code execution result:
['ParentInterface']
See Also
-
the
class_parents
function,
which returns parent classes -
the
class_uses
function,
which returns traits used by a class