How can I pass reference to call_user_func?

callback, php, reference

Solution

I found my answer on the PHP manual :

Note:

Note that the parameters for call_user_func() are not passed by reference.

They also give a trick to do the job :

$x = 42;
call_user_func_array('myTest', array(&$x));

Problem

Consider the following example : ``` function myTest(&$var) { $var++; echo "var = {$var}\n"; } $x = 42; call_user_func('myTest', $x); ``` It shows the warning : Warning: Parameter 1 to myTest() expected to be a reference, value given in /home/alain/workspace/echo/echo.php(57) : eval()'d code on line 7 Note: code written on an online sandbox, explaning the eval. Any idea how I can pass reference to `call_user_func` family functions?

Original source