get_declared_interfaces 関数
関数 get_declared_interfaces は、現在のスクリプト内で宣言された、またはオートロードを通じて読み込まれたすべてのインターフェイス名の配列を返します。
この関数はパラメータを取りません。
構文
get_declared_interfaces();
例
宣言されたすべてのインターフェイスのリストを取得します:
<?php
interface MyInterface1 {}
interface MyInterface2 {}
$res = get_declared_interfaces();
print_r($res);
?>
コードの実行結果:
[..., 'MyInterface1', 'MyInterface2']
例
リストが特定のインターフェイスを含んでいるか確認します:
<?php
interface LoggerInterface {}
$interfaces = get_declared_interfaces();
$res = in_array('LoggerInterface', $interfaces);
var_dump($res);
?>
コードの実行結果:
true
例
新しいインターフェイス宣言前後のインターフェイスリストを比較します:
<?php
$before = get_declared_interfaces();
interface NewInterface {}
$after = get_declared_interfaces();
$res = array_diff($after, $before);
print_r($res);
?>
コードの実行結果:
['NewInterface']
関連項目
-
クラスを返す関数 get_declared_classes
-
トレイトを返す関数 get_declared_traits
-
インターフェイスをチェックする関数 interface_exists
-
クラスのインターフェイスを返す関数 class_implements