php如何判断方法和属性是否存在
时间:2021-10-30 来源:互联网
今天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爱好者其它相关文章!
相关阅读更多 +
-
粤语电影软件哪款强-手机看粤语片神器 2026-01-07 -
什么是UAT测试 UAT测试和SIT的区别和侧重点 2026-01-07 -
漫蛙漫画app最新版本下载安装-漫蛙漫画app官方正版免费下载入口 2026-01-07 -
企查查官网查询入口-企查查官网免费查询入口 2026-01-07 -
逆战未来幽魂骑士怎么打 逆战未来幽魂骑士打法介绍 2026-01-07 -
BIOS设置无法进入的原因分析及解决方案(bios无法进入) 2026-01-07
最近更新