+

PHP Call_user_func () function

Syntax:
mixed call_user_func ($function_name [, mixed $value1 [, mixed $...]])
Mixed here indicates, that the parameter can take several types. 
Parameter:The call_user_func() function takes two types of parameters as above and described below:
  • $function_name:this the name of a function call in the list of a specific function. This is a string parameter.
  • $value:this is a mixed value. One or more parameters to pass to the function.
Return value:This function returns the value returned by the callback function.The following programs illustrate call_user_func() function in PHP:Program 1:function call function GFG ( $value ) { echo "This is $value site." ; } call_user_func ( `GFG` , "GeeksforGeeks" ); call_user_func ( `GFG` , "Content" );  
?>
Exit:
This is GeeksforGeeks site. This is Content site.
Program 2:call_user_func() using namespace name namespace Geeks ; class GFG { static public function demo() { print "GeeksForGeeks" ; } } call_user_func (__ NAMESPACE__. `GFG::demo` );  
// Another way to declare call_user_func ( array (__ NAMESPACE__. ` GFG` , `demo` ));  
?>
Exit:
GeeksForGeeks GeeksForGeeks < / pre> Program 3:Using a class method with call_user_func()       class  GFG {< / code>  static  function  show()   {   echo  "Geeks" ;  } }  $classname  =  "GFG" ;  call_user_func (  $classname .  `:: show` );  
// Another way to use the object $obj = new GFG(); call_user_func ( array ( $obj , `show` ));  
?>
Exit:
Geeks Geeks < / pre> Program 4:Using a lambda function with call_user_func()< table border = "0" cellpadding = "0" cellspacing = "0">      call_user_func (  function  (  $arg ) {  print  "$arg" ;},  `GeeksforGeeks` ); ?>  Exit:
GeeksforGeeks
Links: http: // php.net/manual/en/function.call-user-func.php
Get Solution for free from DataCamp guru