3v4l.org

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

preferences:
46.93 ms | 402 KiB | 5 Q