関数 class_implements

関数 class_implements は、指定されたクラスまたはインターフェースが実装するインターフェース名の配列を返します。 最初のパラメータにはオブジェクトまたは文字列としてのクラス名を渡し、 2番目の省略可能なパラメータはオートロードを使用するかどうかを決定します。

構文

phpclass_implements(
  object|string $class,
  [bool $autoload = true]
): array|false

例

組み込みクラス Exception のインターフェースを取得します:

php<?php
  $res = class_implements('Exception');
  print_r($res);
?>

コードの実行結果:

php['Throwable']

例

独自のインターフェースとクラスを作成し、 実装されたインターフェースを確認します:

php<?php
  interface MyInterface {}
  class MyClass implements MyInterface {}
  
  $res = class_implements('MyClass');
  print_r($res);
?>

コードの実行結果:

php['MyInterface']

例

インターフェース自体のインターフェースを確認します:

php<?php
  interface ParentInterface {}
  interface ChildInterface extends ParentInterface {}
  
  $res = class_implements('ChildInterface');
  print_r($res);
?>

コードの実行結果:

php['ParentInterface']

関連項目