PHP 7
's Closure::call()
has better performance. Its function is to dynamically bind a closure function to a new one.
Object instanceAnd call and execute the function.
Description:
public mixed Closure::call ( object $newthis [, mixed $... ] )
newthis and calls it with any given arguments.
Example before php7:
<?php class A { private $x = 1; } // PHP 7 之前版本定义闭包函数代码 $getXCB = function() { return $this->x; }; // 闭包函数绑定到类 A 上 $getX = $getXCB->bindTo(new A, 'A'); echo $getX(); print(PHP_EOL);
Example after php7:
<?php class A { private $x = 1; } $getX = function() { return $this->x; }; echo $getX->call(new A); ?>
php video tutorial php7 tutorial
The above is the detailed content of Example of using Closure::call in PHP7. For more information, please follow other related articles on the PHP Chinese website!