【发布时间】:2013-04-10 17:51:05
【问题描述】:
这是场景:
我有一个没有预定数量的方法的类。有些是function actionName,有些是function filterName,其中"filter" 和"action" 将定义它们是什么类型的方法,"Name" 可以是任何东西。
在我的__construct() 我想:
$methods = get_class_methods($this);
foreach ( $methods as $method ) {
if ( $method == 'action' )
$this->DoSomething( $this->{$method}() );
if ( $method == 'filter' )
$this->DoSomethingElse( $this->{$method}() );
}
如何在不使用任何类型的字符串或 reg 表达式的情况下实现这一点?
我也愿意使用get_class_methods() 的替代品。但请记住,我永远不会知道有多少 "action" 或 "filter" 方法存在。
【问题讨论】: