1500字范文,内容丰富有趣,写作好帮手!
1500字范文 > php判断成员属性是否存在 PHP判断{函数/类/方法/属性}是否存在

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

时间:2019-03-14 08:47:22

相关推荐

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

1.php判断系统函数或自己写的函数是否存在

bool function_exists ( string $function_name ) 判断函数是否已经定义,例如:if(function_exists('curl_init')){

curl_init();

}else{

echo'notfunctioncurl_init';

}

2.php判断类是否存在

bool class_exists ( string $class_name [, bool $autoload = true ] ) 检查一个类是否已经定义,一定以返回true,否则返回false,例如:if(class_exists('MySQL')){

$myclass=newMySQL();

}

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

bool method_exists ( mixed $object , string $method_name ) 检查类的方法是否存在,例如:$directory=newDirectory;

if(!method_exists($directory,'read')){

echo'未定义read方法!';

}

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

boolproperty_exists(mixed$class,string$property)检查类的属性是否存在,例如:$directory=newDirectory;

if(!property_exists($directory,'li')){

echo'未定义li属性!';

}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。