Skip to content

Commit 9e4c5db

Browse files
committed
Merge branch 'PHP-7.3' into PHP-7.4
* PHP-7.3: Fix #78751: Serialising DatePeriod converts DateTimeImmutable
2 parents 99c84cd + 736cd93 commit 9e4c5db

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
@@ -10,6 +10,7 @@ PHP NEWS
1010

1111
- Date:
1212
. Fixed bug #70153 (\DateInterval incorrectly unserialized). (Maksim Iakunin)
13+
. Fixed bug #78751 (Serialising DatePeriod converts DateTimeImmutable). (cmb)
1314

1415
- FFI:
1516
. Fixed bug #78716 (Function name mangling is wrong for some parameter

ext/date/php_date.c

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

52045204
if (period_obj->start) {
52055205
php_date_obj *date_obj;
5206-
object_init_ex(&zv, date_ce_date);
5206+
object_init_ex(&zv, period_obj->start_ce);
52075207
date_obj = Z_PHPDATE_P(&zv);
52085208
date_obj->time = timelib_time_clone(period_obj->start);
52095209
} else {
@@ -5213,7 +5213,7 @@ static HashTable *date_object_get_properties_period(zval *object) /* {{{ */
52135213

52145214
if (period_obj->current) {
52155215
php_date_obj *date_obj;
5216-
object_init_ex(&zv, date_ce_date);
5216+
object_init_ex(&zv, period_obj->start_ce);
52175217
date_obj = Z_PHPDATE_P(&zv);
52185218
date_obj->time = timelib_time_clone(period_obj->current);
52195219
} else {
@@ -5223,7 +5223,7 @@ static HashTable *date_object_get_properties_period(zval *object) /* {{{ */
52235223

52245224
if (period_obj->end) {
52255225
php_date_obj *date_obj;
5226-
object_init_ex(&zv, date_ce_date);
5226+
object_init_ex(&zv, period_obj->start_ce);
52275227
date_obj = Z_PHPDATE_P(&zv);
52285228
date_obj->time = timelib_time_clone(period_obj->end);
52295229
} else {
@@ -5260,7 +5260,7 @@ static int php_date_period_initialize_from_hash(php_period_obj *period_obj, Hash
52605260

52615261
ht_entry = zend_hash_str_find(myht, "start", sizeof("start")-1);
52625262
if (ht_entry) {
5263-
if (Z_TYPE_P(ht_entry) == IS_OBJECT && Z_OBJCE_P(ht_entry) == date_ce_date) {
5263+
if (Z_TYPE_P(ht_entry) == IS_OBJECT && instanceof_function(Z_OBJCE_P(ht_entry), date_ce_interface)) {
52645264
php_date_obj *date_obj;
52655265
date_obj = Z_PHPDATE_P(ht_entry);
52665266
period_obj->start = timelib_time_clone(date_obj->time);
@@ -5274,7 +5274,7 @@ static int php_date_period_initialize_from_hash(php_period_obj *period_obj, Hash
52745274

52755275
ht_entry = zend_hash_str_find(myht, "end", sizeof("end")-1);
52765276
if (ht_entry) {
5277-
if (Z_TYPE_P(ht_entry) == IS_OBJECT && Z_OBJCE_P(ht_entry) == date_ce_date) {
5277+
if (Z_TYPE_P(ht_entry) == IS_OBJECT && instanceof_function(Z_OBJCE_P(ht_entry), date_ce_interface)) {
52785278
php_date_obj *date_obj;
52795279
date_obj = Z_PHPDATE_P(ht_entry);
52805280
period_obj->end = timelib_time_clone(date_obj->time);
@@ -5287,7 +5287,7 @@ static int php_date_period_initialize_from_hash(php_period_obj *period_obj, Hash
52875287

52885288
ht_entry = zend_hash_str_find(myht, "current", sizeof("current")-1);
52895289
if (ht_entry) {
5290-
if (Z_TYPE_P(ht_entry) == IS_OBJECT && Z_OBJCE_P(ht_entry) == date_ce_date) {
5290+
if (Z_TYPE_P(ht_entry) == IS_OBJECT && instanceof_function(Z_OBJCE_P(ht_entry), date_ce_interface)) {
52915291
php_date_obj *date_obj;
52925292
date_obj = Z_PHPDATE_P(ht_entry);
52935293
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)