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爱好者其它相关文章!
相关阅读更多 +
-
DOGE币最新价格行情与未来走势分析 2025-06-30
-
龙石战争测试服怎么下载-测试资格获取方法 2025-06-30
-
远光84最强武器有哪些-强势枪械推荐 2025-06-30
-
异环是手游还是端游-异环平台属性解答 2025-06-30
-
AI伴侣:在市场逆势上扬后,AIC能否突破0.19美元大关? 2025-06-30
-
龙息神寂黑暗女士有什么技能-黑暗女士技能详细 2025-06-30
最近更新