判断php中的方法是否存在的方法:可以使用method_exists函数来进行判断,如【method_exists($directory,'read')】。如果要判断类中的属性是否已定义,可以使用property_exists函数判断。

相关函数:
(学习视频推荐:java课程)
bool method_exists ( mixed $object , string $method_name ) 检查类的方法是否存在
代码示例:
立即学习“PHP免费学习笔记(深入)”;
$directory=new Directory;
if(!method_exists($directory,'read')) {
echo '未定义read方法!';
}如果要判断类里面的某个属性是否已经定义,在使用如下方法:
bool property_exists ( mixed $class , string $property )检查类的属性是否存在
代码示例:
立即学习“PHP免费学习笔记(深入)”;
$directory=new Directory;
if(!property_exists($directory,'li')) {
echo '未定义li属性!';
}相关推荐:php培训
以上就是判断php中的方法是否存在该怎么做的详细内容,更多请关注php中文网其它相关文章!
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号