所在位置:

首页基础教程程序代码PHP判断{函数/类/方法/属性}是否存在

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

时间:2019-08-23浏览次数:40637TAG:exists  是否  判断  if  string  存在  

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

4.php 判断类里面的某个属性是否已经定义

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

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


相关阅读

加盟热线:

4008-598-678

地址:厦门思明区软件园二期望海路19号之二303

QQ:渠道(907010669),代理(370735343

众企业专注企业网站建设、企业网站制作、企业建网站

全国分站

Copyright © 2016众企业网站建设平台.All Rights Reserved. 闽ICP备15015615号-5   耗时:0.02706s
首页
菜单
代理
版面
全国