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怎么判断类的方法是否存在的详细内容。