array ( 0 => 'index.php', 1 => 'PHP Manual', ), 'head' => array ( 0 => 'UTF-8', 1 => 'zh', ), 'this' => array ( 0 => 'closure.call.php', 1 => 'Closure::call', ), 'up' => array ( 0 => 'class.closure.php', 1 => 'Closure', ), 'prev' => array ( 0 => 'closure.bindto.php', 1 => 'Closure::bindTo', ), 'next' => array ( 0 => 'closure.fromcallable.php', 1 => 'Closure::fromCallable', ), 'alternatives' => array ( ), 'source' => array ( 'lang' => 'zh', 'path' => 'language/predefined/closure/call.xml', ), ); $setup["toc"] = $TOC; $setup["toc_deprecated"] = $TOC_DEPRECATED; $setup["parents"] = $PARENTS; manual_setup($setup); ?>
(PHP 7, PHP 8)
Closure::call — 绑定并调用闭包
newThis
在调用期间将闭包绑定到 object。
args
零个或多个参数,他们将作为参数传递给闭包。
返回闭包的返回值。
示例 #1 Closure::call() 示例
<?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)