[php-src] Issue #8152: Cannot hydrate a DateTime instance created without the constructor

From: Date: Fri, 25 Feb 2022 10:18:11 +0000
Subject: [php-src] Issue #8152: Cannot hydrate a DateTime instance created without the constructor
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-240025@lists.php.net to get a copy of this message
Issue: https://github.com/php/php-src/issues/8152 Comment Author: nicolas-grekas > you can set dummy error handler and remove it after the object is hydrated Well, that's not a proper solution. It will break on PHP 9 if we don't do anything else. Something that works for DateTime* even when dealing with child classes is to call their constructor via reflection: ```php class Foo extends DateTime { } $foo = new Foo(); (new ReflectionMethod('DateTime', '__construct'))->invoke($foo, ...) ``` But for DateInterval and DatePeriod, this doesn't work because their state depends on the way they've been created (using DateTime::diff() or not, etc.) Another solution would be to implement __serialize/__unserialize in PHP 8.2. We'd still have to try to ensure that pre8.2 payloads are still serializable.

« previous php.bugs (#240025) next »