Php/docs/function.method-exists

提供:Dev Guides
< Php
移動先:案内検索

method_exists

(PHP 4, PHP 5, PHP 7)

method_existsクラスメソッドが存在するかどうかを確認する


説明

method_exists ( string|object $object , string $method_name ) : bool

指定した object にクラスメソッドが存在するかどうかを調べます。


パラメータ

object
オブジェクトのインスタンス、あるいはクラス名。
method_name
メソッドの名前。


返り値

method_name で指定したメソッドが 指定した object において定義されている場合に true、そうでない場合に false を返します。


注意

注意:

この関数を使うと、未知のクラスに対しては登録済みの autoloader を使用します。

例1 method_exists() の例

<?php$directory = new Directory('.');var_dump(method_exists($directory,'read'));?>

上の例の出力は以下となります。


bool(true)

例2 静的な method_exists() の例

<?phpvar_dump(method_exists('Directory','read'));?>

上の例の出力は以下となります。


bool(true)

参考

  • function_exists() - 指定した関数が定義されている場合に true を返す
  • is_callable() - 引数が、関数としてコール可能な構造であるかどうかを調べる
  • class_exists() - クラスが定義済みかどうかを確認する