PHP 中的 get_class_methods() 函数

phpprogrammingserver side programming更新于 2025/5/14 2:52:17

get_class_methods() 函数获取类方法的名称。它返回由 name_of_class 指定的类定义的方法名称数组。如果发生错误,则返回 NULL。

语法

get_class_methods(class)

参数

  • name_of_class − 类名。必填!

返回

get_class_methods() 函数返回由 name_of_class 指定的类定义的方法名称数组。如果发生错误,则返回 NULL。

示例

下面是一个例子 −

<?php
class Demo {
   function Demo() {
      return(true);
   }
   function displayOne() {
      return(true);
   }
   function displayTwo() {
      return(true);
   }
}
$method = get_class_methods('Demo');
$method = get_class_methods(new Demo());
foreach ($method as $method_name) {
   echo "$method_name 
"; } ?>

输出

Demo
displayOne
displayTwo

相关文章