The PHP construct
call_user_func_array calls (invokes) a callback and passes the parameters to it. The parameters are wrapped in an array and then assigned one-by-one to the callback’s parameter list. You are calling the callback by the full qualified name given to it in the first parameter. If the callback returns a value, then that value is returned by
Watch these videos first
- The callable to be called (invoked).
- An indexed array of parameter(s) to be passed to the callback.
If the callback returns a value, then
call_user_func_array returns that value; else it returns
NULL. On error, it returns
Show It in ActionBasic
Let’s see the
call_user_func_array function in action. In this video, you will see how it works.
When was the last time you got out of your chair and stretched? Just saying…
In these videos, you will go deeper into the instruction. You will look at the PHP source code, discuss how memory is managed for the parameters, and look at passing by reference.
How do you call object and static methods with
call_user_func_array? How do you call closures?
See It In Popular TechnologiesPro
When do you use
call_user_func_array versus one of the other ways to call a callback?