$this comes along
A method returns a closure, and another returns a static closure.
<?phpclass Counter{ private int $n = 0; public function incrementer(): Closure { return function () { return ++$this->n; }; } public function detached(): Closure { return static function () { return isset($this) ? 'has $this' : 'no $this'; }; }}$c = new Counter();$inc = $c->incrementer();$inc();echo $inc(), PHP_EOL;echo ($c->detached())(), PHP_EOL;1. Predict the output
Tap the lines in the order you think they print.
- 1…
- 2…