method_exists
クラスメソッドが存在するかどうかを確認する
説明
bool method_exists(objectstring $object_or_class, string $method)
パラメータ
-
object_or_class
-
オブジェクトのインスタンス、あるいはクラス名。
-
method
-
メソッドの名前。
戻り値
method で指定したメソッドが
指定した object_or_class において定義されている場合に
true、そうでない場合に false を返します。
例
例1 method_exists の例
<?php
$directory = new Directory('.');
var_dump(method_exists($directory,'read'));
?>
例2 staticメソッドに対する method_exists の例
<?php
var_dump(method_exists('Directory','read'));
?>
注意
注意:
この関数を使うと、未知のクラスに対しては登録済みの
autoloader を使用します。
注意:
マジックメソッド __call を使ってアクセス可能なメソッドを、method_exists は検知できません。
参考
- function_exists
- is_callable
- class_exists