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欧易App十大热门币种推荐 投资必看精选榜单 2025-10-28 -
网络热梗什么压力是什么梗揭秘 年轻人减压神梗爆火原因 2025-10-28 -
伊莫辉石怎么获取-伊莫辉石获取方式汇总 2025-10-28 -
一梦江湖暗香血月兰花坐标-全成就及逃课方法 2025-10-28 -
剑侠世界4无限是手游吗-手游平台详细 2025-10-28 -
忘川风华录名士邓绥技能解析-邓绥基本玩法 2025-10-28
最近更新