PHP7 Closure::call()

Closure::call()

Closure::call() is a more performant, shorthand way of temporarily binding an object scope to a closure and invoking it.It is much faster in performance as compared to bindTo of PHP 5.6.

<?php
class A {  private $x = 1; }
 // Pre PHP 7 code
 $getX = function() { return $this->x;};
 $getXCB = $getX->bindTo(new A, 'A');// intermediate closure
 echo $getXCB();
 // PHP 7+ code
 $getX = function() { return $this->x;};
 echo $getX->call(new A);
 ?>
 

Output:

1
1