method_exists
(PHP 4, PHP 5, PHP 7, PHP 8)
method_exists — 检查类的方法是否存在
说明
检查类的方法是否存在于指定的 object_or_class 中。
参数
object_or_class-
对象示例或者类名
method-
方法名
更新日志
| 版本 | 说明 |
|---|---|
| 7.4.0 |
针对继承的私有方法的类检查现在返回 false。
|
示例
示例 #1 method_exists() 示例
<?php
$directory = new Directory('.');
var_dump(method_exists($directory,'read'));
?>以上示例会输出:
bool(true)
示例 #2 静态 method_exists() 示例
<?php
var_dump(method_exists('Directory','read'));
?>以上示例会输出:
bool(true)
参见
- function_exists() - 如果给定的函数已经被定义就返回 true
- is_callable() - 验证值是否可以在当前范围内作为函数调用
- class_exists() - 查类是否已经定义