Reputation: 22810
$controller->$method($this->params);
ok the problem is that my $this->params
is an array, is there something in php that can we do so it will be like
$controller->$method($params1,$params2,$untilllastparams); ?
thanks for looking in
Adam Ramadhan
Upvotes: 1
Views: 101
Reputation: 2233
You could try using the eval and "implode" functions (http://php.net/manual/en/function.implode.php). Basically implode your array as a comma delimited string (this will represent your method parameters) and then build a string like so,
$implodedString = implode(",", $this->params);
eval("$controller->$method($implodedString);")
It's likely not the most ideal solution, and I don't have any way to test it right now, but give it a go.
Upvotes: 0
Reputation: 1573
You are looking for call_user_func_array(). In your example this would look like:
call_user_func_array(array($controller, $method), $this->params);
http://php.net/manual/en/function.call-user-func-array.php
Upvotes: 3
Reputation:
I assume that controller is some library class and you are looking for a different interface. One solution is to define a wrapper function:
function my_wrapper(ControllerClass &$controller, &$params1, &$params2, &$untilllastparams) {
// create array from parameters
$controller->$method($param_array);
};
Upvotes: 0