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 $this->work(function() { return $this->increment(); }); } public function increment() { return $this->x++; } public function work($callback) { return $callback(); } public function getX() { return $this->x; } } $a = new A(1); $b = $a->get(); var_dump($a->getX());

preferences:
32.4 ms | 402 KiB | 5 Q