Though as always I expect there will be something I have missed.. unfortunately I couldn't avoid the use of eval() altogether, but this may just have been able to negate any need to worry.. if I haven't missed anything of course.
This example uses a dynamic method call to demonstrate, but the logic applies for any parameter/arguments passing.
Code: Select all
<?php
class A
{
private function __call ($name, $args)
{
$str = '';
foreach ($args as $arg => $val) {
$str .= ', $prefix_' . $arg;
}
extract($args, EXTR_PREFIX_ALL, 'prefix');
eval('$this->bar(' . substr($str, 2) . ');');
}
public function bar ($a, $b, $c)
{
var_dump(func_get_args());
}
}
$a = new A;
$a->foo(1,2,3);
?>Code: Select all
$this->bar($prefix_0, $prefix_1, $prefix_2);Code: Select all
array(3) {
[0]=>
int(1)
[1]=>
int(2)
[2]=>
int(3)
}