3v4l.org

run code in 300+ PHP versions simultaneously
<?php class X { var $value; function get() { return null !== $this->value ? $this->value : ($this->value = $this->getLongCalculation()); } function getLongCalculation() { sleep(1); return 5; } } $x = new X; var_dump($x->get()); var_dump($x->get());

preferences:
43.4 ms | 402 KiB | 5 Q