The What
Description
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 call_user_func_array
.
Watch these videos first
Before you tackle call_user_func_array
, make sure you first watch callable and callback. call_user_func_array
works on both of these constructs.
Parameters
callback
- The callable to be called (invoked).
parameter
- An indexed array of parameter(s) to be passed to the callback.
Return Values
If the callback returns a value, then call_user_func_array
returns that value; else it returns NULL
. On error, it returns FALSE
.
Show It in ActionBasic
Let’s see the call_user_func_array
function in action. In this video, you will see how it works.
There’s a time to code and …. yup, that sums it up.
Go DeepPro
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.
Calling MethodsPro
How do you call object and static methods with call_user_func_array
? How do you call closures?
See It In Popular TechnologiesPro
Let’s look at call_user_func_array
in Laravel, Symfony, and WordPress. You will see how prevalent it is used.
WhenPro
When do you use call_user_func_array
versus one of the other ways to call a callback?