(PHP 4, PHP 5, PHP 7, PHP 8)
method_exists — クラスメソッドが存在するかどうかを確認する
$object_or_class, string $method): bool
指定した object_or_class にクラスメソッドが存在するかどうかを調べます。
object_or_classオブジェクトのインスタンス、あるいはクラス名。
methodメソッドの名前。
method で指定したメソッドが
指定した object_or_class において定義されている場合に
true、そうでない場合に false を返します。
例1 method_exists() の例
<?php
$directory = new Directory('.');
var_dump(method_exists($directory,'read'));
?>
上の例の出力は以下となります。
bool(true)
例2 staticメソッドに対する method_exists() の例
<?php
var_dump(method_exists('Directory','read'));
?>
上の例の出力は以下となります。
bool(true)
注意:
この関数を使うと、未知のクラスに対しては登録済みの autoloader を使用します。