PHP での function_exists と method_exists の違いは何ですか?
function_existsは関数があるかどうかを判断し、method_existsはクラスのメソッドがあるかどうかを判断します。
その具体的な違いは次のとおりです。
- function_existsはグローバル関数、method_existsはクラスのメソッドに対して用いる。
- function_existsはパラメータとして関数名を、method_existsはパラメータとしてクラス名とメソッド名を指定する。
- function_existsは関数が存在するかどうかの真偽値を返し、method_existsはメソッドが存在するかどうかの真偽値を返します。
- function_existsは任意の関数に使用できますが、method_existsはクラスメソッドにしか使えません。
関数とメソッドの有無を判定する関数としては、function_existsやmethod_existsがあるが、利用場面が異なる。