您的位置:首页 > 编程语言 > PHP开发

PHP检测文件方法,类方法是否存在

2017-02-09 19:28 537 查看

PHP检测文件方法,类方法是否存在

(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 classname[,boolautoload = true ] ) 检查一个类是否已经定义,一定以返回true,否则返回false,例如:

if(class_exists('MySQL')){
$myclass=new MySQL();
}


(3)php判断类里面的某个方法是否已经定义

bool method_exists ( mixed object,stringmethod_name ) 检查类的方法是否存在,例如:

$directory=new Directory;
if(!method_exists($directory,'read')){
echo '未定义read方法!';
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  php