php怎么检查类方法是否存在

来自:互联网
时间:2021-07-06
阅读:

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

代码示例:

<?php
$directory = new Directory('.');
var_dump(method_exists($directory,'read'));
?>

以上例程会输出:

bool(true)

示例2

<?php
var_dump(method_exists('Directory','read'));
?>

以上例程会输出:

bool(true)
返回顶部
顶部