php如何判断方法和属性是否存在

php如何判断方法和属性是否存在,第1张

php如何判断方法和属性是否存在

php判断方法和属性是否存在的方法:【method_exists(mixed $object,string $method_name );property_exists(mixed $class,string $property);】。

本文 *** 作环境:windows10系统、php 7、thinkpad t480电脑。

php判断类里面的某个方法是否存在:

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

$directory=new Directory;
if(!method_exists($directory,'read')){
    echo '未定义read方法!';
}

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

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

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

推荐学习:php培训

以上就是php如何判断方法和属性是否存在的详细内容,

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/680687.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-04-20
下一篇 2022-04-20

发表评论

登录后才能评论

评论列表(0条)

保存