3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Foo { public string $bar = 'a'; public ?string $baz = null; public function __construct(public readonly ?string $x = null) { } } $foo = new Foo(); $fooSerialized = 'O:3:"Foo":1:{s:3:"bar";s:1:"a";}a'; $fooUnserialized = unserialize($fooSerialized); var_dump($fooUnserialized->bar); // works because exists in serialized string var_dump($fooUnserialized->baz); // works because regular typed property, even if not existing in serialized string var_dump($fooUnserialized->x); // Doesn't work
Output for 8.3.5 - 8.3.27, 8.4.1 - 8.4.14
Warning: unserialize(): Extra data starting at offset 32 of 33 bytes in /in/4d6XG on line 14 string(1) "a" NULL Fatal error: Uncaught Error: Typed property Foo::$x must not be accessed before initialization in /in/4d6XG:18 Stack trace: #0 {main} thrown in /in/4d6XG on line 18
Process exited with code 255.
Output for 8.1.30 - 8.1.33, 8.2.6 - 8.2.29
string(1) "a" NULL Fatal error: Uncaught Error: Typed property Foo::$x must not be accessed before initialization in /in/4d6XG:18 Stack trace: #0 {main} thrown in /in/4d6XG on line 18
Process exited with code 255.

preferences:
78.23 ms | 408 KiB | 5 Q