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.32, 8.4.1 - 8.4.24, 8.5.0 - 8.5.9
slow 42 42 42
Output for 8.0.29, 8.1.0 - 8.1.34, 8.2.0 - 8.2.32
Fatal error: Constant expression contains invalid operations in /in/Dfn5j on line 11
Process exited with code 255.

preferences:
67.53 ms | 1044 KiB | 4 Q