PHP での function_exists と method_exists の違いは何ですか?

function_existsは関数があるかどうかを判断し、method_existsはクラスのメソッドがあるかどうかを判断します。

その具体的な違いは次のとおりです。

  1. function_existsはグローバル関数、method_existsはクラスのメソッドに対して用いる。
  2. function_existsはパラメータとして関数名を、method_existsはパラメータとしてクラス名とメソッド名を指定する。
  3. function_existsは関数が存在するかどうかの真偽値を返し、method_existsはメソッドが存在するかどうかの真偽値を返します。
  4. function_existsは任意の関数に使用できますが、method_existsはクラスメソッドにしか使えません。

関数とメソッドの有無を判定する関数としては、function_existsやmethod_existsがあるが、利用場面が異なる。

bannerAds