Did my research on this, couldn’t find what I was looking for. Tried ReflectionClass but that didn’t work for me.
I have a class with functions. The number of variables going into the function is dynamic.
Example:
Included class:
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);
So what I am trying to achieve, is to take the array of variables and send them to the function test as so in the code example, where I can list each one.
This example below does what I would like to do, but how would I apply it to a class/mvc framework?
$colors = array('test','maroon','blue','green');
call_user_func_array('setLineColor', $colors);
function setLinecolor($var1, $var2, $var3, $var4){
echo $var1;
echo $var2;
}
Any thoughts on this?
Use a proper callback for the object:
This will invoke the
test()function on the$fooobject.