从PHP对象获取以子字符串开头的所有方法名称 [英] Get all method names starting with a substring from a PHP object

查看:85
本文介绍了从PHP对象获取以子字符串开头的所有方法名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个对象,想要一个方法,该方法返回该对象以bla_开头的方法.

I have an object and want a method that returns how much method this Object have that start with bla_.

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

I found get_class_methods() which returns all method names, but I only want names which starts with bla_

推荐答案

您可以使用

You can use preg_grep() to filter them:

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

这篇关于从PHP对象获取以子字符串开头的所有方法名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆