|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2019-10-25 11:32 UTC] michael dot heerklotz at web dot de
Description:
------------
When serialising (serialize()) a DatePeriod object which has been initialised with DateTimeImmutable instances, the DateTimeImmutable type gets lost, and is converted to DateTime
Test script:
---------------
<?php
$oDay = new DateTimeImmutable('2019-10-25');
$oDateInterval = DateInterval::createFromDateString('1 day');
$oDays = new DatePeriod($oDay, $oDateInterval, $oDay->modify('+1 day'));
print serialize($oDays);
// Output: O:10:"DatePeriod":6:{s:5:"start";O:8:"DateTime": ...
Expected result:
----------------
O:10:"DatePeriod":6:{s:5:"start";O:8:"DateTimeImmutable":3:{s:4:"date";s:26:"2019-10-25 00:00:00.000000";s:13:"timezone_type";i:3;s:8:"timezone";s:10:"US/Pacific";}s:7:"current";N;s:3:"end";O:8:"DateTimeImmutable":3:{s:4:"date";s:26:"2019-10-26 00:00:00.000000";s:13:"timezone_type";i:3;s:8:"timezone";s:10:"US/Pacific";}s:8:"interval";O:12:"DateInterval":16:{s:1:"y";i:0;s:1:"m";i:0;s:1:"d";i:1;s:1:"h";i:0;s:1:"i";i:0;s:1:"s";i:0;s:1:"f";d:0;s:7:"weekday";i:0;s:16:"weekday_behavior";i:0;s:17:"first_last_day_of";i:0;s:6:"invert";i:0;s:4:"days";b:0;s:12:"special_type";i:0;s:14:"special_amount";i:0;s:21:"have_weekday_relative";i:0;s:21:"have_special_relative";i:0;}s:11:"recurrences";i:1;s:18:"include_start_date";b:1;}2019-10-25
Actual result:
--------------
O:10:"DatePeriod":6:{s:5:"start";O:8:"DateTime":3:{s:4:"date";s:26:"2019-10-25 00:00:00.000000";s:13:"timezone_type";i:3;s:8:"timezone";s:10:"US/Pacific";}s:7:"current";N;s:3:"end";O:8:"DateTime":3:{s:4:"date";s:26:"2019-10-26 00:00:00.000000";s:13:"timezone_type";i:3;s:8:"timezone";s:10:"US/Pacific";}s:8:"interval";O:12:"DateInterval":16:{s:1:"y";i:0;s:1:"m";i:0;s:1:"d";i:1;s:1:"h";i:0;s:1:"i";i:0;s:1:"s";i:0;s:1:"f";d:0;s:7:"weekday";i:0;s:16:"weekday_behavior";i:0;s:17:"first_last_day_of";i:0;s:6:"invert";i:0;s:4:"days";b:0;s:12:"special_type";i:0;s:14:"special_amount";i:0;s:21:"have_weekday_relative";i:0;s:21:"have_special_relative";i:0;}s:11:"recurrences";i:1;s:18:"include_start_date";b:1;}2019-10-25
PatchesPull Requests
Pull requests:
HistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Oct 28 08:00:01 2025 UTC |
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