【发布时间】:2012-08-16 02:16:27
【问题描述】:
我对此进行了研究,找不到我想要的东西。尝试了 ReflectionClass,但这对我不起作用。
我有一个带有函数的类。进入函数的变量数量是动态的。
例子:
包含的类:
class Home {
function test($var1, $var2, $var3){
// do stuff here
}
}
// this class is included based on url params, i.e. example.com/home/test/1/2/3
// where home is class, test is function and 1 2 3 are variables
$variables = array('1','2','3'); // static for this example, but array can have any number of elements to it.
$foo = new Home();
$foo->test($variables);
call_user_func_array('test', $variables);
所以我想要实现的是获取变量数组并将它们发送到函数测试,就像代码示例中那样,我可以在其中列出每个变量。
下面的这个例子做了我想做的事,但我如何将它应用到类/mvc 框架中?
$colors = array('test','maroon','blue','green');
call_user_func_array('setLineColor', $colors);
function setLinecolor($var1, $var2, $var3, $var4){
echo $var1;
echo $var2;
}
对此有什么想法吗?
【问题讨论】: