3v4l.org

run code in 500+ PHP versions simultaneously
<?php class X { private string $_x; public string $x { get => $this->_x; } public function __construct(string $x) { $this->_x = $x; } public function setX(string $x) { $this->_x = $x; } } class Y extends X { public string $x { set(string $value) {$this->setX($value);} } } $x = new X('test'); var_dump($x); $y = new Y('test 2'); var_dump($y->x); $y->x = 'test 3'; var_dump($y->x); $x->x = 'test 4';
Output for 8.3.5
Parse error: syntax error, unexpected token "{", expecting "," or ";" in /in/CRYJa on line 6
Process exited with code 255.
Output for 8.4.1
object(X)#1 (1) { ["_x":"X":private]=> string(4) "test" } string(6) "test 2" string(6) "test 3" Fatal error: Uncaught Error: Property X::$x is read-only in /in/CRYJa:34 Stack trace: #0 {main} thrown in /in/CRYJa on line 34
Process exited with code 255.

preferences:
28.73 ms | 1139 KiB | 6 Q