ReflectionFunction::invoke()函数是PHP中的内置函数,用于返回调用函数的结果。
用法:
mixed ReflectionFunction::invoke( mixed $args)
参数:该函数接受参数$args,该参数保存传递给被调用函数的参数列表。
返回值:该函数返回调用函数的结果。
以下示例程序旨在说明PHP中的ReflectionFunction::invoke()函数:
程序_1:
// Initializing a user-defined function
function Company($Company_Name, $Role) {
return sprintf("%s %s\r\n", $Company_Name, $Role);
}
// Using ReflectionFunction() over the
// specified function company
$function = new ReflectionFunction('company');
// Calling the invoke() function
$A = $function->invoke('GeeksforGeeks',
'is a Computer Science Portal.');
// Getting the result of the invoked function company
echo $A;
?>
输出:
GeeksforGeeks is a Computer Science Portal.
程序_2:
// Initializing some user-defined functions
function Trial1($First_Args, $Second_Args) {
return sprintf("%s %s\r\n", $First_Args, $Second_Args);
}
function Trial2($First_Args, $Second_Args) {
return sprintf("%s %s\r\n", $First_Args, $Second_Args);
}
// Using ReflectionFunction() over the above
// specified functions
$function = new ReflectionFunction('Trial1');
$function = new ReflectionFunction('Trial2');
// Calling the invoke() function and getting the
// result of the invoked function company
echo $function->invoke('a+a', '= 2a');
echo $function->invoke('a*a', '= a^2');
?>
输出:
a+a = 2a
a*a = a^2