The PHP construct
call_user_func calls (invokes) a callback and passes the parameters (if any) to it. 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).
- Parameter(s) to be passed to the callback. Specify them by the needs of the callback, i.e. based on its parameter list.
If the callback returns a value, then
call_user_func returns that value; else it returns
NULL. On error, it returns
Show It in ActionBasic
Let’s see the
call_user_func function in action. In this video, you will see how it works.
Who needs copy/paste? Right. Writing code from scratch is fun!
In this video, you will go deeper into the instruction.
How do you call object and static methods with
call_user_func? How do you call closures?
See It In Popular TechnologiesPro
When do you use
call_user_func versus one of the other ways to call a callback?