3v4l.org

run code in 300+ PHP versions simultaneously
<?php class A { private $x; public function __construct($v) { $this->x = $v; } public function getIncrementor() { return function() { return ++$this->x; }; } } $a = new A(1); $b = $a->getIncrementor(); var_dump($b());

preferences:
47.43 ms | 402 KiB | 5 Q