PHP判断函数,类,方法,属性是否存在

php 判断类里面的某个属性是否已经定义
bool property_exists ( mixed $class , string $property )检查类的属性是否存在

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

php判断系统函数或自己写的函数是否存在
bool function_exists ( string $function_name ) 判断函数是否已经定义

if (function_exists('curl_init')) {
    curl_init();
} else {
    echo 'not function curl_init';
}

php判断类是否存在
bool class_exists ( string $class_name [, bool $autoload = true ] ) 检查一个类是否已经定义,一定以返回true,否则返回false

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

php判断类里面的某个方法是否已经定义
bool method_exists ( mixed $object , string $method_name ) 检查类的方法是否存在

$directory = new Directory;
if (!method_exists($directory,'read')) {
    echo '未定义read方法!';
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值