com php-src: Fix #78751: Serialising DatePeriod converts DateTimeImmutable: NEWS ext/date/php_date.c ext/date/tests/bug7875 1.phpt
| From: | Christoph Michael Becker | Date: | Mon, 28 Oct 2019 12:07:28 +0000 |
| Subject: | com php-src: Fix #78751: Serialising DatePeriod converts DateTimeImmutable: NEWS ext/date/php_date.c ext/date/tests/bug7875 1.phpt | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-109089@lists.php.net to get a copy of this message | ||
Commit: 89c327f8848c1a56a61479ee5e7fdd3694d0f867
Author: Christoph M. Becker <cmbecker69@gmx.de> Fri, 25 Oct 2019 15:43:38 +0200
Parents: 16c49108763db251151b350e433dde6d1a076250
Branches: PHP-7.2 PHP-7..3 PHP-7.4 master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=89c327f8848c1a56a61479ee5e7fdd3694d0f867
Log:
Fix #78751: Serialising DatePeriod converts DateTimeImmutable
When getting the properties of a DatePeriod instance we have to retain
the proper classes, and when restoring a DatePeriod instance we have to
cater to DateTimeImmutable instances as well.
Bugs:
https://bugs.php.net/78751
Changed paths:
M NEWS
M ext/date/php_date.c
A ext/date/tests/bug78751.phpt
Diff:
diff --git a/NEWS b/NEWS
index 1d5c6d3d7c3..6fba02d9c88 100644
--- a/NEWS
+++ b/NEWS
@@ -13,6 +13,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 f82abc64867..fdf84f60567 100644
--- a/ext/date/php_date.c
+++ b/ext/date/php_date.c
@@ -5171,7 +5171,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 {
@@ -5181,7 +5181,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 {
@@ -5191,7 +5191,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 {
@@ -5228,7 +5228,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);
@@ -5242,7 +5242,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);
@@ -5255,7 +5255,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--
+<?php
+$oDay = new DateTimeImmutable('2019-10-25');
+$oDateInterval = DateInterval::createFromDateString('1 day');
+$oDays = new DatePeriod($oDay, $oDateInterval, $oDay->modify('+1 day'));
+$oDays = unserialize(serialize($oDays));
+var_dump(
+ $oDays->start instanceof DateTimeImmutable,
+ $oDays->end instanceof DateTimeImmutable
+);
+?>
+--EXPECT--
+bool(true)
+bool(true)