[php-src] Issue #11354: promoted property in serialized object behaves unexpected

From: Date: Thu, 01 Jun 2023 10:02:36 +0000
Subject: [php-src] Issue #11354: promoted property in serialized object behaves unexpected
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-244583@lists.php.net to get a copy of this message
Issue: https://github.com/php/php-src/issues/11354 Author: R4c00n ### Description The following code: ```php <?php class Foo { public string $bar = 'a'; public ?string $baz = null; public function __construct(public readonly ?string $x = null) { } } $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 ``` Resulted in this output: ``` 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. ``` But I expected this output instead: ``` string(1) "a" NULL NULL ``` See also https://3v4l.org/4d6XG#v8.2.6 (all versions) ### PHP Version PHP 8.2.6 ### Operating System _No response_

« previous php.bugs (#244583) next »