Last Updated: February 25, 2016
·
1.507K
· yaodong

PHP call_user_func() and call_user_func_array() parameters

The parameters for call_user_func() and call_user_func_array() are not passed by reference.

$function = function (&$p) {
    echo $p;
};
$param = '123';

call_user_func($function, $param);
// or
call_user_func_array($function, [$param]);

You'll get an error message as PHP Warning: Parameter 1 to {closure}() expected to be a reference, value given.

To fix this, you can use this instead:

$function($param);
// or
call_user_func_array($function, [&$param]);