class a
{
public function f(&$ref1, &$ref2)
{
$ref1 = 'foo';
$ref2 = 'bar';
}
}
class b
{
public function __call($methodName, $arguments)
{
$a = new a();
call_user_func_array(array(
$a, $methodName
), $arguments);
}
}
$ref1 = 'X';
$ref2 = 'Y';
$b = new b();
$b->f($ref1, $ref2);
var_dump($ref1, $ref2);
This results in:
PHP Warning: Parameter 1 to a::f() expected to be a reference, value given in /home/jon/sync_workspace/bugsync/tests/test.php on line 18
PHP Stack trace:
PHP 1. {main}() /test.php:0
PHP 2. b->f() /test.php:23
PHP 3. b->__call() /test.php:23
PHP 4. call_user_func_array() /test.php:17
string(1) "X"
string(1) "Y"
How can I accomplish the above in PHP 5.4 (manipulate ref1 and ref2 by use of reference)?
In PHP 5.3 I used the & syntax at $b->f(&$ref1, &$ref2);
(even though it's deprecated), but in PHP5.4 this throws fatal error.