当尝试使用任意一组参数在子类中调用函数时,我遇到了以下问题:
class Base{
function callDerived($method,$params){
call_user_func_array(array($this,$method),$params);
}
}
class Derived extends Base{
function test($foo,$bar){
print "foo=$foo, bar=$bar\n";
}
}
$d = new Derived();
$d->callDerived('test',array('bar'=>'2','foo'=>1));
输出:
foo=2, bar=1
我想知道是否有一种方法可以实现我的需求,而不必重新组合带有func_get_args索引顺序的数组。当然,我可以直接传递整个数组并在函数中处理它...但那不是我想要做的事情。
谢谢
call_user_func_array()
函数:可以直接使用call_user_func('func', $array['foo'], $array['bar']);
。 - KingCrunch