(PHP 4, PHP 5, PHP 7, PHP 8)
method_exists — 檢查類的方法是否存在
object
對(duì)象示例或者類名。
method_name
方法名。
如果 method_name
所指的方法在 object
所指的對(duì)象類中已定義,則返回 true
,否則返回 false
。
注意:
如果此類不是已知類,使用此函數(shù)會(huì)使用任何已注冊(cè)的 autoloader。
示例 #1 method_exists() 例子
<?php
$directory = new Directory('.');
var_dump(method_exists($directory,'read'));
?>
以上例程會(huì)輸出:
bool(true)
示例 #2 Static method_exists() 例子
<?php
var_dump(method_exists('Directory','read'));
?>
以上例程會(huì)輸出:
bool(true)