3v4l.org

run code in 300+ PHP versions simultaneously
<?php /* // Original definition readonly class Foo { public function __construct(private string $a) {} } var_dump(bin2hex(serialize(new Foo("foo")))); // 4f3a333a22466f6f223a313a7b733a363a2200466f6f0061223b733a333a22666f6f223b7d */ // New definition, 'a' is no longer required. readonly class Foo { public function __construct() {} } var_dump(unserialize(hex2bin('4f3a333a22466f6f223a313a7b733a363a2200466f6f0061223b733a333a22666f6f223b7d')));
Output for 8.2.21 - 8.2.29, 8.3.5 - 8.3.26, 8.4.1 - 8.4.13
Fatal error: Uncaught Error: Cannot create dynamic property Foo::$a in /in/Xsmfu:18 Stack trace: #0 /in/Xsmfu(18): unserialize('O:3:"Foo":1:{s:...') #1 {main} thrown in /in/Xsmfu on line 18
Process exited with code 255.
Output for 8.1.0 - 8.1.33
Parse error: syntax error, unexpected token "readonly", expecting end of file in /in/Xsmfu on line 14
Process exited with code 255.
Output for 8.0.1 - 8.0.23
Parse error: syntax error, unexpected token "class" in /in/Xsmfu on line 14
Process exited with code 255.
Output for 7.4.0 - 7.4.30
Parse error: syntax error, unexpected 'class' (T_CLASS) in /in/Xsmfu on line 14
Process exited with code 255.

preferences:
65.89 ms | 409 KiB | 5 Q