3v4l.org

run code in 300+ PHP versions simultaneously
<?php class C { public readonly string $full; public function __construct( public readonly string $first, public readonly string $last, ) { unset($this->full); } public function __get(string $key) { print __FUNCTION__ . PHP_EOL; if ($key === 'full') { $this->full = "$this->first $this->last"; return $this->full; } } } $c = new C('Larry', 'Garfield'); print $c->first . PHP_EOL; print $c->full . PHP_EOL; print $c->full . PHP_EOL;
Output for 8.1.30 - 8.1.34, 8.2.23 - 8.2.30, 8.3.5 - 8.3.30, 8.4.1 - 8.4.18, 8.5.0 - 8.5.3
Larry __get Larry Garfield Larry Garfield
Output for 8.0.0 - 8.0.12
Parse error: syntax error, unexpected identifier "string", expecting variable in /in/Y2hei on line 4
Process exited with code 255.
Output for 7.4.0 - 7.4.25
Parse error: syntax error, unexpected 'string' (T_STRING), expecting variable (T_VARIABLE) in /in/Y2hei on line 4
Process exited with code 255.
Output for 7.3.0 - 7.3.32
Parse error: syntax error, unexpected 'readonly' (T_STRING), expecting function (T_FUNCTION) or const (T_CONST) in /in/Y2hei on line 4
Process exited with code 255.

preferences:
63.79 ms | 1008 KiB | 4 Q