Bug #78751 [Csd]: serialize() converts DateTimeImmutable to DateTime when serialising DatePeriod

From: Date: Thu, 28 Nov 2019 22:27:45 +0000
Subject: Bug #78751 [Csd]: serialize() converts DateTimeImmutable to DateTime when serialising DatePeriod
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-223925@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=78751&edit=1 ID: 78751 Updated by: cmb@php.net Reported by: michael dot heerklotz at web dot de Summary: serialize() converts DateTimeImmutable to DateTime when serialising DatePeriod Status: Closed Type: Bug Package: Date/time related Operating System: Ubuntu PHP Version: 7.3.11 Assigned To: cmb Block user comment: N Private report: N New Comment: Few bug fixes are backwards compatible, and in my opinion, the former behavior was a bug. Anyhow, if you feel this commit should be reverted for PHP 7.3, I'm not strongly opposed, but would suggest to discuss this on the internals mailing list. [1] <https://www.php.net/mailing-lists.php#internals> Previous Comments: ------------------------------------------------------------------------ [2019-11-28 20:47:40] cory dot jacobsen at 7shifts dot com This is not a backwards compatible change. Our company just updated from 7.3.11 to 7.3.12 and this broke a lot of tests and production code. Not sure what we can do at this point... ------------------------------------------------------------------------ [2019-10-28 12:10:33] cmb@php.net Automatic comment on behalf of cmbecker69@gmx.de Revision: http://git.php.net/?p=php-src.git;a=commit;h=89c327f8848c1a56a61479ee5e7fdd3694d0f867 Log: Fix #78751: Serialising DatePeriod converts DateTimeImmutable ------------------------------------------------------------------------ [2019-10-25 12:46:10] cmb@php.net The following pull request has been associated: Patch Name: Fix #78751: Serialising DatePeriod converts DateTimeImmutable On GitHub: https://github.com/php/php-src/pull/4859 Patch: https://github.com/php/php-src/pull/4859.patch ------------------------------------------------------------------------ [2019-10-25 12:15:54] cmb@php.net Confirmed: <https://3v4l.org/WaCMr>. This is, however, not particularly related to serialization, but rather a general issue regarding the get_properties handler, which unconditionally creates $start and $end as DateTime instances[1]. [1] <https://github.com/php/php-src/blob/php-7.3.11/ext/date/php_date.c#L5157> ------------------------------------------------------------------------ [2019-10-25 12:14:17] michael dot heerklotz at web dot de I just realised, that my "Expected result" is misleading. So here is another example code: Test script: --------------- <?php $oDay = new DateTimeImmutable('2019-10-25'); $oDateInterval = DateInterval::createFromDateString('1 day'); $oDays = new DatePeriod($oDay, $oDateInterval, $oDay->modify('+1 day')); print 'Before serialize():' . PHP_EOL; foreach ($oDays as $oDay) { print $oDay->modify('+1 day')->format('Y-m-d') . PHP_EOL; print $oDay->format('Y-m-d') . PHP_EOL; } print 'After serialize():' . PHP_EOL; $oDaysSerialized = unserialize(serialize($oDays)); foreach ($oDaysSerialized as $oDay) { print $oDay->modify('+1 day')->format('Y-m-d') . PHP_EOL; print $oDay->format('Y-m-d') . PHP_EOL; } Expected result: ---------------- Before serialize(): 2019-10-26 2019-10-25 After serialize(): 2019-10-26 2019-10-25 Actual result: -------------- Before serialize(): 2019-10-26 2019-10-25 After serialize(): 2019-10-26 2019-10-26 ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at https://bugs.php.net/bug.php?id=78751 -- Edit this bug report at https://bugs.php.net/bug.php?id=78751&edit=1

« previous php.bugs (#223925) next »