php怎么判断类的方法是否存在

王林
王林 原创
2023-03-03 17:10:01 3329浏览

php判断类的方法是否存在的方法:可以利用method_exists()函数进行判断。函数语法:【method_exists(mixed $object,string $method_name)】,如果方法在对象类中已定义,则返回TRUE。

method_exists()检查类的方法是否存在。如果 method_name 所指的方法在 object 所指的对象类中已定义,则返回 TRUE,否则返回 FALSE。

(推荐教程:php图文教程

函数语法:

bool method_exists(mixed $object, string $method_name)

(视频教程推荐:php视频教程

代码实现:

$directory=new Directory;
if(!method_exists($directory,'read')){
    echo '未定义read方法!';
}

以上就是php怎么判断类的方法是否存在的详细内容,更多请关注php中文网其它相关文章!

声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。