array ( 0 => 'index.php', 1 => 'PHP Manual', ), 'head' => array ( 0 => 'UTF-8', 1 => 'zh', ), 'this' => array ( 0 => 'function.method-exists.php', 1 => 'method_exists', ), 'up' => array ( 0 => 'ref.classobj.php', 1 => '类/对象 函数', ), 'prev' => array ( 0 => 'function.is-subclass-of.php', 1 => 'is_subclass_of', ), 'next' => array ( 0 => 'function.property-exists.php', 1 => 'property_exists', ), 'alternatives' => array ( ), 'source' => array ( 'lang' => 'zh', 'path' => 'reference/classobj/functions/method-exists.xml', ), ); $setup["toc"] = $TOC; $setup["toc_deprecated"] = $TOC_DEPRECATED; $setup["parents"] = $PARENTS; manual_setup($setup); ?>
(PHP 4, PHP 5, PHP 7, PHP 8)
method_exists — 检查类的方法是否存在
检查类的方法是否存在于指定的 object_or_class
中。
object_or_class
对象示例或者类名
method
方法名
示例 #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。