Open In App

PHP | call_user_func() Function

Last Updated : 25 Jun, 2018
Comments
Improve
Suggest changes
2 Likes
Like
Report
The call_user_func() is an inbuilt function in PHP which is used to call the callback given by the first parameter and passes the remaining parameters as argument. It is used to call the user-defined functions. Syntax:
mixed call_user_func ( $function_name[, mixed $value1[, mixed $... ]])
Here, mixed indicates that a parameter may accept multiple types. Parameter: The call_user_func() function accepts two types of parameters as mentioned above and described below:
  • $function_name: It is the name of function call in the list of defined function. It is a string type parameter.
  • $value: It is mixed value. One or more parameters to be passed to the function.
Return Value: This function returns the value returned by the callback function. Below programs illustrate the call_user_func() function in PHP: Program 1: Call the function
Output:
This is GeeksforGeeks site.
This is Content site.
Program 2: call_user_func() using namespace name
Output:
GeeksForGeeks
GeeksForGeeks
Program 3: Using a class method with call_user_func()
Output:
Geeks
Geeks
Program 4: Using lambda function with call_user_func()
Output:
GeeksforGeeks
References: http://php.net/manual/en/function.call-user-func.php

Next Article
Practice Tags :

Similar Reads