php - 从 PHP 对象中获取所有以子字符串开头的方法名称

标签 php class oop object

我有一个对象,想要一个方法来返回这个对象有多少以 bla_ 开头的方法。

我发现 get_class_methods() 返回所有方法名称,但我只想要以 bla_ 开头的名称

最佳答案

您可以使用 preg_grep()过滤它们:

$method_names = preg_grep('/^bla_/', get_class_methods($object));

关于php - 从 PHP 对象中获取所有以子字符串开头的方法名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1826503/

相关文章:

php - 在 MySQL 中找不到 outfile 创建的文件

javascript - 如何使用ajax创建目录并在其中上传文件?

c++ - 模板和单独编译

c# 构造函数错误 "CS1061" "x does not contain a definition for y"

python - Pylint 错误 W0232 : class has no __init__ method

oop - vbscript静态类变量/方法?

php - Kohana 3.2 中的 $this->request->param() 和 $this->request->post()

php - HTML 净化器保留空间

perl 构造函数关键字 'new'

c# - C#中的委托(delegate)和继承