I went through PHP 7.0 changes and came across Closing a call . The code in the documentation is as follows.
<?php class A {private $x = 1;} // Pre PHP 7 code $getXCB = function() {return $this->x;}; // this line $getX = $getXCB->bindTo(new A, 'A'); // intermediate closure echo $getX();
My question is: how can a line after the first comment return x? Doesn't that break encapsulation?
It seems that when x is mentioned inside the closure of the function, for some reason we are actually in the scope of the class.
source share