関数 class_implements
関数 class_implements は、指定されたクラスまたはインターフェースが実装するインターフェース名の配列を返します。
最初のパラメータにはオブジェクトまたは文字列としてのクラス名を渡し、
2番目の省略可能なパラメータはオートロードを使用するかどうかを決定します。
構文
class_implements(
object|string $class,
[bool $autoload = true]
): array|false
例
組み込みクラス Exception のインターフェースを取得します:
<?php
$res = class_implements('Exception');
print_r($res);
?>
コードの実行結果:
['Throwable']
例
独自のインターフェースとクラスを作成し、 実装されたインターフェースを確認します:
<?php
interface MyInterface {}
class MyClass implements MyInterface {}
$res = class_implements('MyClass');
print_r($res);
?>
コードの実行結果:
['MyInterface']
例
インターフェース自体のインターフェースを確認します:
<?php
interface ParentInterface {}
interface ChildInterface extends ParentInterface {}
$res = class_implements('ChildInterface');
print_r($res);
?>
コードの実行結果:
['ParentInterface']
関連項目
-
親クラスを返す関数
class_parents,
-
クラスが使用するトレイトを返す関数
class_uses,