PHP Closure::call()
PHP Closure::call()
PHP 7’s Closure::call() has better performance and dynamically binds a closure function to a new object instance and call the function.
Example
Example
x; }; // 闭包函数绑定到类 A 上 $getX = $getXCB->bindTo(new A, 'A'); echo $getX(); print(PHP_EOL); // PHP 7+ 代码 $getX = function() { return $this->x; }; echo $getX->call(new A); ?>
The execution output of the above program is:
1
1
1