(1)php判断系统函数或自己写的函数是否存在
bool function_exists ( string $function_name ) 判断函数是否已经定义,例如:
if(function_exists('curl_init')){ curl_init(); }else{ echo 'not function curl_init'; }
(2)php判断类是否存在
bool class_exists ( string $class_name [, bool $autoload = true ] ) 检查一个类是否已经定义,一定以返回true,否则返回false,例如:
if(class_exists('MySQL')){ $myclass=new MySQL(); }
(3)php判断类里面的某个方法是否已经定义
bool method_exists ( mixed $object , string $method_name ) 检查类的方法是否存在,例如:
$directory=new Directory; if(!method_exists($directory,'read')){ echo '未定义read方法!'; }
本文介绍了PHP中如何使用内置函数来检测特定的类、函数及类方法是否存在。包括使用`function_exists`来检查函数是否定义,使用`class_exists`验证类是否存在,以及通过`method_exists`确认类的方法是否已定义。

被折叠的 条评论
为什么被折叠?



