get_declared_interfaces 関数

関数 get_declared_interfaces は、現在のスクリプト内で宣言された、またはオートロードを通じて読み込まれたすべてのインターフェイス名の配列を返します。 この関数はパラメータを取りません。

構文

phpget_declared_interfaces();

例

宣言されたすべてのインターフェイスのリストを取得します:

php<?php
  interface MyInterface1 {}
  interface MyInterface2 {}
  
  $res = get_declared_interfaces();
  print_r($res);
?>

コードの実行結果:

php[..., 'MyInterface1', 'MyInterface2']

例

リストが特定のインターフェイスを含んでいるか確認します:

php<?php
  interface LoggerInterface {}
  
  $interfaces = get_declared_interfaces();
  $res = in_array('LoggerInterface', $interfaces);
  var_dump($res);
?>

コードの実行結果:

phptrue

例

新しいインターフェイス宣言前後のインターフェイスリストを比較します:

php<?php
  $before = get_declared_interfaces();
  interface NewInterface {}
  $after = get_declared_interfaces();
  
  $res = array_diff($after, $before);
  print_r($res);
?>

コードの実行結果:

php['NewInterface']

関連項目