3v4l.org

run code in 500+ PHP versions simultaneously
<?php class LazyValue { public function __construct( private Closure $lazy, ){} public function getValue() { static $value = ($this->lazy)(); return $value; } } $t1 = new LazyValue(function () { echo "slow\n"; return "42\n"; }); echo $t1->getValue(); echo $t1->getValue(); echo $t1->getValue();
Output for 8.3.0 - 8.3.31, 8.4.1 - 8.4.22, 8.5.0 - 8.5.7
slow 42 42 42
Output for 8.0.29, 8.1.0 - 8.1.34, 8.2.0 - 8.2.31
Fatal error: Constant expression contains invalid operations in /in/Dfn5j on line 11
Process exited with code 255.

preferences:
60.03 ms | 1020 KiB | 4 Q