method_exists

(PHP 4, PHP 5, PHP 7, PHP 8)

method_exists检查类的方法是否存在

说明

method_exists(object|string $object_or_class, string $method): bool

检查类的方法是否存在于指定的 object_or_class 中。

参数

object_or_class

对象示例或者类名

method

方法名

返回值

如果 method 所指的方法在 object_or_class 所指的对象类中已定义,则返回 true,否则返回 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)

注释

注意:

如果此类不是已知类,使用此函数会使用任何已注册的 autoloader

参见

add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top