这里做一个动态函数、类和类方法的判断是否存在,然后调用
(1)系统和自定义函数判断
bool function_exists ( string $function_name )
判断函数是否已经定义,例如:
if(function_exists('test')){
test();
}else{
echo 'not function test';
}
(2)类判断
bool class_exists ( string $class_name [, bool $autoload = true ] )
检查一个类是否已经定义,一定以返回true,否则返回false,例如:
if(class_exists('MySQL')){
$myclass=new MySQL();
}
(3)判断类的某个方法是否已经定义
bool method_exists ( mixed $object , string $method_name )
检查类的方法是否存在,例如:
$hClass = new hello();
if(!method_exists($hClass ,'write')) {
echo '未定义write方法!';
}
更多详情,请参考 PHP 官方手册