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

preferences:
42.02 ms | 402 KiB | 5 Q