This question already has an answer here:
Clearly this is really poor code, but I can't think how to improve it. The 'test' function can't be changed at all, but all the rest can.
I want to pass an array of values to one function that actions the test function. The key thing is I need to make use of all pre-defined function variable values in the test function without redeclaring them.
I can't action the test function directly, it must go through another function.
This is just a demo of a much bigger problem, but solving this will definitely solve my problem. If it can't be done I need to completely re-think many things.
function test($p1, $p2="hello", $p3=5, $p4=true) {
}
--
function action($vars = array()) {
$count = count($vars);
switch($count) {
case 1:
$result = test($vars[0]);
break;
case 2:
$result = test($vars[0], $vars[1]);
break;
case 3:
$result = test($vars[0], $vars[1], $vars[2]);
break;
case 4:
$result = test($vars[0], $vars[1], $vars[2], $vars[3]);
break;
}
return $result;
}
--
action(array(1, "test"));
</div>