L O A D I N G
«

PHP判断{函数/类/方法/属性}是否存在

童话里,我们在一起 发布于 阅读:532 PHP


1.php判断系统函数或自己写的函数是否存在文章来源站点https://www.yii666.com/

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方法!';
}

4.php 判断类里面的某个属性是否已经定义文章来源地址https://www.yii666.com/article/555294.html

bool property_exists ( mixed $class , string $property )检查类的属性是否存在,例如:

$directory=new Directory;
if(!property_exists($directory,'li')){
echo '未定义li属性!';
}

版权声明:本文内容来源于网络,版权归原作者所有,此博客不拥有其著作权,亦不承担相应法律责任。文本页已经标记具体来源原文地址,请点击原文查看来源网址,站内文章以及资源内容站长不承诺其正确性,如侵犯了您的权益,请联系站长如有侵权请联系站长,将立刻删除


扫描二维码,在手机上阅读
收藏