class_implements
Description
The class_implements of SPL for PHP returns the interfaces which are implemented by the given class or interface.
Syntax
class_implements( object|string $object_or_class, bool $autoload = true ): array|false
Parameters
object_or_class
An object (class instance) or a string (class or interface name).
autoload
Whether to autoload if not already loaded.
Return
Returns an array on success, or false when the given class doesn't exist.
Examples
1 · object_or_class · object
<? interface myinterface { } class myclass implements myinterface { } $object_or_class = new myclass; $return = class_implements($object_or_class); print_r($return); ?>
Array ( [myinterface] => myinterface )
2 · object_or_class · class
<? interface myinterface { } class myclass implements myinterface { } $object_or_class = "myclass"; $return = class_implements($object_or_class); print_r($return); ?>
Array ( [myinterface] => myinterface )
3 · autoload · false
<? spl_autoload_register(); interface myinterface { } class myclass implements myinterface { } $object_or_class = "myclass"; $autoload = false; $return = class_implements($object_or_class, $autoload); print_r($return); ?>
Array ( [myinterface] => myinterface )
4 · autoload · true
<? spl_autoload_register(); interface myinterface { } class myclass implements myinterface { } $object_or_class = "myclass"; $autoload = true; $return = class_implements($object_or_class, $autoload); print_r($return); ?>
Array ( [myinterface] => myinterface )
5 · multiple
<? interface myinterface1 { } interface myinterface2 { } interface myinterface3 { } class myclass implements myinterface1, myinterface2, myinterface3 { } $object_or_class = "myclass"; $return = class_implements($object_or_class); print_r($return); ?>
Array ( [myinterface1] => myinterface1 [myinterface2] => myinterface2 [myinterface3] => myinterface3 )
6 · multiple · extends
<? interface myinterface1 { } interface myinterface2 extends myinterface1 { } interface myinterface3 extends myinterface2 { } interface myinterface4 extends myinterface3 { } class myclass implements myinterface4 { } $object_or_class = "myclass"; $return = class_implements($object_or_class); print_r($return); ?>
Array ( [myinterface4] => myinterface4 [myinterface2] => myinterface2 [myinterface1] => myinterface1 [myinterface3] => myinterface3 )