method_exists
(PHP 4, PHP 5, PHP 7, PHP 8)
method_exists — 檢查類的方法是否存在
參數
-
object
-
對像示例或者類名。
-
method_name
-
方法名。
返回值
如果 method_name
所指的方法在 object
所指的對象類中已定義,則返回 true
,否則返回 false
。
註釋
注意:
如果此類不是已知類,使用此函式會使用任何已註冊的 autoloader。
範例
示例 #1 method_exists() 例子
<?php
$directory = new Directory('.');
var_dump(method_exists($directory,'read'));
?>
以上例程會輸出:
bool(true)
示例 #2 Static method_exists() 例子
<?php
var_dump(method_exists('Directory','read'));
?>
以上例程會輸出:
bool(true)
參見
- function_exists() - 如果給定的函式已經被定義就返回 true
- is_callable() - 檢測參數是否為合法的可呼叫結構
- class_exists() - 檢查類是否已定義