我有这个:
class A
{
public function ok($a,$b)
{
echo __METHOD__.'<br>';
var_dump($a,$b);
}
public function reference(&$a)
{
echo __METHOD__.'<br>';
$a = 'cameFromReference';
}
}
class B
{
/**
* @var A
*/
private $decorated;
public function __construct(A $decorated)
{
$this->decorated = $decorated;
}
public function __call($name, $args)
{
return call_user_func_array([$this->decorated, $name], $args);
}
}
echo '<pre>';
$b = new B(new A());
$b->ok('test', 'test2');
$a = -1;
$b->reference($a);
var_dump($a);
使用__call
,我想转移方法调用。一切正常,直到我必须通过(并获得)参考。即使我改为:
return call_user_func_array([$this->decorated, $name], [&$args]);
然后传递错误的参数数量。