在php中,可以使用method_exists()函数来判断类中是否定义了指定方法。

示例:

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

说明:

method_exists()函数可以检查类的指定方法是否存在。语法:

method_exists(mixed $object, string $method_name): bool

该函数会检查类的方法是否存在于指定的 object中。

  • object:对象示例或者类名。

  • method_name:方法名。

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。