[php-src] Issue #10152: Custom properties of DateTimeImmutable child classes are not serialized
| From: | derrabus | Date: | Thu, 22 Dec 2022 10:52:52 +0000 |
| Subject: | [php-src] Issue #10152: Custom properties of DateTimeImmutable child classes are not serialized | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-243220@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/10152
Author: derrabus
### Description
The following code:
```php
<?php
class MyDateTimeImmutable extends DateTimeImmutable {
public function __construct(
string $datetime = "now",
?DateTimeZone $timezone = null,
public ?bool $myProperty = null,
) {
parent::__construct($datetime, $timezone);
}
}
$datetime = new MyDateTimeImmutable('2022-12-22T11:26:00Z', myProperty: true);
$serialized = serialize($datetime);
$unserialized = unserialize($serialized);
var_dump($unserialized->myProperty);
```
Resulted in this output:
```
Fatal error: Uncaught Error: Typed property MyDateTimeImmutable::$myProperty must not be accessed
before initialization in /path/to/file.php:17
Stack trace:
#0 {main}
thrown in /path/to/file.php on line 17
```
But I expected this output instead:
```
bool(true)
```
The propblem can be observed here: https://3v4l.org/8q4Or
Apparently,
MyDateTimeImmutable::$myProperty is not included in the serialized string
anymore on PHP 8.2.0. On PHP 8.0/8.1, it does appear there and is unserialized properly.
### PHP Version
PHP 8.2.0
### Operating System
_No response_