3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Foo { public int $bar { get => $this->bar; set => empty($this->bar) ? $this->bar = $value : throw new LogicException("nope"); } } $foo = new Foo(); $foo->bar = 42; echo $foo->bar . "\n"; $foo->bar += 1;
Output for 8.4.10
42 Fatal error: Uncaught LogicException: nope in /in/2JagR:6 Stack trace: #0 /in/2JagR(14): Foo->$bar::set(43) #1 {main} thrown in /in/2JagR on line 6
Process exited with code 255.

preferences:
151.3 ms | 995 KiB | 7 Q