Skip to content

Commit 736cd93

Browse files
committed
Merge branch 'PHP-7.2' into PHP-7.3
* PHP-7.2: Fix #78751: Serialising DatePeriod converts DateTimeImmutable
2 parents b61b60d + 89c327f commit 736cd93

File tree

3 files changed

+23
-6
lines changed

3 files changed

+23
-6
lines changed

NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ PHP NEWS
1414

1515
- Date:
1616
. Fixed bug #70153 (\DateInterval incorrectly unserialized). (Maksim Iakunin)
17+
. Fixed bug #78751 (Serialising DatePeriod converts DateTimeImmutable). (cmb)
1718

1819
- Iconv:
1920
. Fixed bug #78642 (Wrong libiconv version displayed). (gedas at martynas,

ext/date/php_date.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5168,7 +5168,7 @@ static HashTable *date_object_get_properties_period(zval *object) /* {{{ */
51685168

51695169
if (period_obj->start) {
51705170
php_date_obj *date_obj;
5171-
object_init_ex(&zv, date_ce_date);
5171+
object_init_ex(&zv, period_obj->start_ce);
51725172
date_obj = Z_PHPDATE_P(&zv);
51735173
date_obj->time = timelib_time_clone(period_obj->start);
51745174
} else {
@@ -5178,7 +5178,7 @@ static HashTable *date_object_get_properties_period(zval *object) /* {{{ */
51785178

51795179
if (period_obj->current) {
51805180
php_date_obj *date_obj;
5181-
object_init_ex(&zv, date_ce_date);
5181+
object_init_ex(&zv, period_obj->start_ce);
51825182
date_obj = Z_PHPDATE_P(&zv);
51835183
date_obj->time = timelib_time_clone(period_obj->current);
51845184
} else {
@@ -5188,7 +5188,7 @@ static HashTable *date_object_get_properties_period(zval *object) /* {{{ */
51885188

51895189
if (period_obj->end) {
51905190
php_date_obj *date_obj;
5191-
object_init_ex(&zv, date_ce_date);
5191+
object_init_ex(&zv, period_obj->start_ce);
51925192
date_obj = Z_PHPDATE_P(&zv);
51935193
date_obj->time = timelib_time_clone(period_obj->end);
51945194
} else {
@@ -5225,7 +5225,7 @@ static int php_date_period_initialize_from_hash(php_period_obj *period_obj, Hash
52255225

52265226
ht_entry = zend_hash_str_find(myht, "start", sizeof("start")-1);
52275227
if (ht_entry) {
5228-
if (Z_TYPE_P(ht_entry) == IS_OBJECT && Z_OBJCE_P(ht_entry) == date_ce_date) {
5228+
if (Z_TYPE_P(ht_entry) == IS_OBJECT && instanceof_function(Z_OBJCE_P(ht_entry), date_ce_interface)) {
52295229
php_date_obj *date_obj;
52305230
date_obj = Z_PHPDATE_P(ht_entry);
52315231
period_obj->start = timelib_time_clone(date_obj->time);
@@ -5239,7 +5239,7 @@ static int php_date_period_initialize_from_hash(php_period_obj *period_obj, Hash
52395239

52405240
ht_entry = zend_hash_str_find(myht, "end", sizeof("end")-1);
52415241
if (ht_entry) {
5242-
if (Z_TYPE_P(ht_entry) == IS_OBJECT && Z_OBJCE_P(ht_entry) == date_ce_date) {
5242+
if (Z_TYPE_P(ht_entry) == IS_OBJECT && instanceof_function(Z_OBJCE_P(ht_entry), date_ce_interface)) {
52435243
php_date_obj *date_obj;
52445244
date_obj = Z_PHPDATE_P(ht_entry);
52455245
period_obj->end = timelib_time_clone(date_obj->time);
@@ -5252,7 +5252,7 @@ static int php_date_period_initialize_from_hash(php_period_obj *period_obj, Hash
52525252

52535253
ht_entry = zend_hash_str_find(myht, "current", sizeof("current")-1);
52545254
if (ht_entry) {
5255-
if (Z_TYPE_P(ht_entry) == IS_OBJECT && Z_OBJCE_P(ht_entry) == date_ce_date) {
5255+
if (Z_TYPE_P(ht_entry) == IS_OBJECT && instanceof_function(Z_OBJCE_P(ht_entry), date_ce_interface)) {
52565256
php_date_obj *date_obj;
52575257
date_obj = Z_PHPDATE_P(ht_entry);
52585258
period_obj->current = timelib_time_clone(date_obj->time);

ext/date/tests/bug78751.phpt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
--TEST--
2+
Bug #78751 (Serialising DatePeriod converts DateTimeImmutable)
3+
--FILE--
4+
<?php
5+
$oDay = new DateTimeImmutable('2019-10-25');
6+
$oDateInterval = DateInterval::createFromDateString('1 day');
7+
$oDays = new DatePeriod($oDay, $oDateInterval, $oDay->modify('+1 day'));
8+
$oDays = unserialize(serialize($oDays));
9+
var_dump(
10+
$oDays->start instanceof DateTimeImmutable,
11+
$oDays->end instanceof DateTimeImmutable
12+
);
13+
?>
14+
--EXPECT--
15+
bool(true)
16+
bool(true)

0 commit comments

Comments
 (0)