Skip to content

Commit f9a98f6

Browse files
committed
Merge branch 'PHP-7.4'
* PHP-7.4: Fix #78751: Serialising DatePeriod converts DateTimeImmutable
2 parents 84f2a98 + 9e4c5db commit f9a98f6

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

ext/date/php_date.c

+6-6
Original file line numberDiff line numberDiff line change
@@ -4793,7 +4793,7 @@ static HashTable *date_object_get_properties_period(zend_object *object) /* {{{
47934793

47944794
if (period_obj->start) {
47954795
php_date_obj *date_obj;
4796-
object_init_ex(&zv, date_ce_date);
4796+
object_init_ex(&zv, period_obj->start_ce);
47974797
date_obj = Z_PHPDATE_P(&zv);
47984798
date_obj->time = timelib_time_clone(period_obj->start);
47994799
} else {
@@ -4803,7 +4803,7 @@ static HashTable *date_object_get_properties_period(zend_object *object) /* {{{
48034803

48044804
if (period_obj->current) {
48054805
php_date_obj *date_obj;
4806-
object_init_ex(&zv, date_ce_date);
4806+
object_init_ex(&zv, period_obj->start_ce);
48074807
date_obj = Z_PHPDATE_P(&zv);
48084808
date_obj->time = timelib_time_clone(period_obj->current);
48094809
} else {
@@ -4813,7 +4813,7 @@ static HashTable *date_object_get_properties_period(zend_object *object) /* {{{
48134813

48144814
if (period_obj->end) {
48154815
php_date_obj *date_obj;
4816-
object_init_ex(&zv, date_ce_date);
4816+
object_init_ex(&zv, period_obj->start_ce);
48174817
date_obj = Z_PHPDATE_P(&zv);
48184818
date_obj->time = timelib_time_clone(period_obj->end);
48194819
} else {
@@ -4850,7 +4850,7 @@ static int php_date_period_initialize_from_hash(php_period_obj *period_obj, Hash
48504850

48514851
ht_entry = zend_hash_str_find(myht, "start", sizeof("start")-1);
48524852
if (ht_entry) {
4853-
if (Z_TYPE_P(ht_entry) == IS_OBJECT && Z_OBJCE_P(ht_entry) == date_ce_date) {
4853+
if (Z_TYPE_P(ht_entry) == IS_OBJECT && instanceof_function(Z_OBJCE_P(ht_entry), date_ce_interface)) {
48544854
php_date_obj *date_obj;
48554855
date_obj = Z_PHPDATE_P(ht_entry);
48564856
period_obj->start = timelib_time_clone(date_obj->time);
@@ -4864,7 +4864,7 @@ static int php_date_period_initialize_from_hash(php_period_obj *period_obj, Hash
48644864

48654865
ht_entry = zend_hash_str_find(myht, "end", sizeof("end")-1);
48664866
if (ht_entry) {
4867-
if (Z_TYPE_P(ht_entry) == IS_OBJECT && Z_OBJCE_P(ht_entry) == date_ce_date) {
4867+
if (Z_TYPE_P(ht_entry) == IS_OBJECT && instanceof_function(Z_OBJCE_P(ht_entry), date_ce_interface)) {
48684868
php_date_obj *date_obj;
48694869
date_obj = Z_PHPDATE_P(ht_entry);
48704870
period_obj->end = timelib_time_clone(date_obj->time);
@@ -4877,7 +4877,7 @@ static int php_date_period_initialize_from_hash(php_period_obj *period_obj, Hash
48774877

48784878
ht_entry = zend_hash_str_find(myht, "current", sizeof("current")-1);
48794879
if (ht_entry) {
4880-
if (Z_TYPE_P(ht_entry) == IS_OBJECT && Z_OBJCE_P(ht_entry) == date_ce_date) {
4880+
if (Z_TYPE_P(ht_entry) == IS_OBJECT && instanceof_function(Z_OBJCE_P(ht_entry), date_ce_interface)) {
48814881
php_date_obj *date_obj;
48824882
date_obj = Z_PHPDATE_P(ht_entry);
48834883
period_obj->current = timelib_time_clone(date_obj->time);

ext/date/tests/bug78751.phpt

+16
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)