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]);
Written by Yaodong Zhao
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Php
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#