クラスをインスタンス化しなくても、特定のメソッドの存在を確認することもできます
echo method_exists( bob, 'yippie' ) ? 'yes' : 'no';
さらに一歩進んで、「yippie」が実際に静的であることを確認したい場合は、Reflection APIを使用します(PHP5 のみ) 。
try {
$method = new ReflectionMethod( 'bob::yippie' );
if ( $method->isStatic() )
{
// verified that bob::yippie is defined AND static, proceed
}
}
catch ( ReflectionException $e )
{
// method does not exist
echo $e->getMessage();
}
または、2 つのアプローチを組み合わせることができます
if ( method_exists( bob, 'yippie' ) )
{
$method = new ReflectionMethod( 'bob::yippie' );
if ( $method->isStatic() )
{
// verified that bob::yippie is defined AND static, proceed
}
}