php中的invoke,PHP ReflectionFunction invoke()用法及代码示例

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值