diff --git a/NEWS b/NEWS index c4e05157546..c03d16720cc 100644 --- a/NEWS +++ b/NEWS @@ -14,6 +14,7 @@ PHP NEWS - Date: . Fixed bug #70153 (\DateInterval incorrectly unserialized). (Maksim Iakunin) + . Fixed bug #78751 (Serialising DatePeriod converts DateTimeImmutable). (cmb) - Iconv: . Fixed bug #78642 (Wrong libiconv version displayed). (gedas at martynas, diff --git a/ext/date/php_date.c b/ext/date/php_date.c index 49df94f5925..00656a41f97 100644 --- a/ext/date/php_date.c +++ b/ext/date/php_date.c @@ -5168,7 +5168,7 @@ static HashTable *date_object_get_properties_period(zval *object) /* {{{ */ if (period_obj->start) { php_date_obj *date_obj; - object_init_ex(&zv, date_ce_date); + object_init_ex(&zv, period_obj->start_ce); date_obj = Z_PHPDATE_P(&zv); date_obj->time = timelib_time_clone(period_obj->start); } else { @@ -5178,7 +5178,7 @@ static HashTable *date_object_get_properties_period(zval *object) /* {{{ */ if (period_obj->current) { php_date_obj *date_obj; - object_init_ex(&zv, date_ce_date); + object_init_ex(&zv, period_obj->start_ce); date_obj = Z_PHPDATE_P(&zv); date_obj->time = timelib_time_clone(period_obj->current); } else { @@ -5188,7 +5188,7 @@ static HashTable *date_object_get_properties_period(zval *object) /* {{{ */ if (period_obj->end) { php_date_obj *date_obj; - object_init_ex(&zv, date_ce_date); + object_init_ex(&zv, period_obj->start_ce); date_obj = Z_PHPDATE_P(&zv); date_obj->time = timelib_time_clone(period_obj->end); } else { @@ -5225,7 +5225,7 @@ static int php_date_period_initialize_from_hash(php_period_obj *period_obj, Hash ht_entry = zend_hash_str_find(myht, "start", sizeof("start")-1); if (ht_entry) { - if (Z_TYPE_P(ht_entry) == IS_OBJECT && Z_OBJCE_P(ht_entry) == date_ce_date) { + if (Z_TYPE_P(ht_entry) == IS_OBJECT && instanceof_function(Z_OBJCE_P(ht_entry), date_ce_interface)) { php_date_obj *date_obj; date_obj = Z_PHPDATE_P(ht_entry); 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 ht_entry = zend_hash_str_find(myht, "end", sizeof("end")-1); if (ht_entry) { - if (Z_TYPE_P(ht_entry) == IS_OBJECT && Z_OBJCE_P(ht_entry) == date_ce_date) { + if (Z_TYPE_P(ht_entry) == IS_OBJECT && instanceof_function(Z_OBJCE_P(ht_entry), date_ce_interface)) { php_date_obj *date_obj; date_obj = Z_PHPDATE_P(ht_entry); 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 ht_entry = zend_hash_str_find(myht, "current", sizeof("current")-1); if (ht_entry) { - if (Z_TYPE_P(ht_entry) == IS_OBJECT && Z_OBJCE_P(ht_entry) == date_ce_date) { + if (Z_TYPE_P(ht_entry) == IS_OBJECT && instanceof_function(Z_OBJCE_P(ht_entry), date_ce_interface)) { php_date_obj *date_obj; date_obj = Z_PHPDATE_P(ht_entry); period_obj->current = timelib_time_clone(date_obj->time); diff --git a/ext/date/tests/bug78751.phpt b/ext/date/tests/bug78751.phpt new file mode 100644 index 00000000000..6021b9f6aec --- /dev/null +++ b/ext/date/tests/bug78751.phpt @@ -0,0 +1,16 @@ +--TEST-- +Bug #78751 (Serialising DatePeriod converts DateTimeImmutable) +--FILE-- +modify('+1 day')); +$oDays = unserialize(serialize($oDays)); +var_dump( + $oDays->start instanceof DateTimeImmutable, + $oDays->end instanceof DateTimeImmutable +); +?> +--EXPECT-- +bool(true) +bool(true)