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爱好者其它相关文章!
-
PHP中ignore_user_abort()函数详解 时间:2025-08-19
-
PHP中linkinfo()函数详解 时间:2025-08-19
-
CSS border-collapse属性的使用方法 时间:2025-08-19
-
CSS3动画animation属性详解 animation、transition和transform的区别 时间:2025-08-19
-
jQquery中slideDown()、slideUp()和slideToggle()方法详解及使用 时间:2025-08-19
-
CSS中background-color属性详解 时间:2025-08-19
今日更新
-
杖剑传说全27食谱配方及加成属性效果
阅读:18
-
快来当领主英雄升级的顺序是什么
阅读:18
-
仙遇清虚灵宠最佳搭配组合是什么
阅读:18
-
爱氏物语蜜露森林隐藏支线怎么触发
阅读:18
-
吞天食地666之不负众望苏小月方天戟怎么获得
阅读:18
-
PEAK游戏怎么复活队友
阅读:18
-
迷城陆区小爆哥礼包码是多少
阅读:18
-
华夏千秋养猪的方法合成配方
阅读:18
-
迷城陆区复活香波怎么获得
阅读:18
-
遮天凡尘一叶天命流派阵容怎么搭配
阅读:18