Closure::call
(PHP 7)
Closure::call - 绑定并调用闭包
描述
public mixed Closure::call ( object $newthis [, mixed $... ] )
暂时将闭包绑定到newthis
,并用任何给定的参数调用。
参数
newthis
在调用期间绑定闭包的对象。
...
零个或多个参数,这些参数将作为闭包的参数给出。
返回值
返回闭包的返回值。
示例
Example #1 Closure::call() example
<?php
class?Value?{
????protected?$value;
????public?function?__construct($value)?{
????????$this->value?=?$value;
????}
????public?function?getValue()?{
????????return?$this->value;
????}
}
$three?=?new?Value(3);
$four?=?new?Value(4);
$closure?=?function?($delta)?{?var_dump($this->getValue()?+?$delta);?};
$closure->call($three,?4);
$closure->call($four,?4);
?>
上面的例子将输出:
int(7)
int(8)
← Closure::bindTo
Closure::fromCallable →
本文档系腾讯云开发者社区成员共同维护,如有问题请联系 cloudcommunity@tencent.com