Skip to content

Commit 1bddd4e

Browse files
committed
Merge branch 'PHP-8.2'
2 parents 788540e + 57417bb commit 1bddd4e

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-0
lines changed

ext/date/php_date.c

+20
Original file line numberDiff line numberDiff line change
@@ -5489,6 +5489,11 @@ static bool php_date_period_initialize_from_hash(php_period_obj *period_obj, Has
54895489
if (Z_TYPE_P(ht_entry) == IS_OBJECT && instanceof_function(Z_OBJCE_P(ht_entry), date_ce_interface)) {
54905490
php_date_obj *date_obj;
54915491
date_obj = Z_PHPDATE_P(ht_entry);
5492+
5493+
if (!date_obj->time) {
5494+
return 0;
5495+
}
5496+
54925497
if (period_obj->start != NULL) {
54935498
timelib_time_dtor(period_obj->start);
54945499
}
@@ -5506,6 +5511,11 @@ static bool php_date_period_initialize_from_hash(php_period_obj *period_obj, Has
55065511
if (Z_TYPE_P(ht_entry) == IS_OBJECT && instanceof_function(Z_OBJCE_P(ht_entry), date_ce_interface)) {
55075512
php_date_obj *date_obj;
55085513
date_obj = Z_PHPDATE_P(ht_entry);
5514+
5515+
if (!date_obj->time) {
5516+
return 0;
5517+
}
5518+
55095519
if (period_obj->end != NULL) {
55105520
timelib_time_dtor(period_obj->end);
55115521
}
@@ -5522,6 +5532,11 @@ static bool php_date_period_initialize_from_hash(php_period_obj *period_obj, Has
55225532
if (Z_TYPE_P(ht_entry) == IS_OBJECT && instanceof_function(Z_OBJCE_P(ht_entry), date_ce_interface)) {
55235533
php_date_obj *date_obj;
55245534
date_obj = Z_PHPDATE_P(ht_entry);
5535+
5536+
if (!date_obj->time) {
5537+
return 0;
5538+
}
5539+
55255540
if (period_obj->current != NULL) {
55265541
timelib_time_dtor(period_obj->current);
55275542
}
@@ -5538,6 +5553,11 @@ static bool php_date_period_initialize_from_hash(php_period_obj *period_obj, Has
55385553
if (Z_TYPE_P(ht_entry) == IS_OBJECT && Z_OBJCE_P(ht_entry) == date_ce_interval) {
55395554
php_interval_obj *interval_obj;
55405555
interval_obj = Z_PHPINTERVAL_P(ht_entry);
5556+
5557+
if (!interval_obj->initialized) {
5558+
return 0;
5559+
}
5560+
55415561
if (period_obj->interval != NULL) {
55425562
timelib_rel_time_dtor(period_obj->interval);
55435563
}

ext/date/tests/bug-gh11416.phpt

+42
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ date.timezone=UTC
55
--FILE--
66
<?php
77
$now = new DateTimeImmutable();
8+
$simpleInterval = new DateInterval("P2D");
89

910
$date = (new ReflectionClass(DateTime::class))->newInstanceWithoutConstructor();
1011
try {
@@ -20,9 +21,50 @@ try {
2021
echo get_class($e), ': ', $e->getMessage(), "\n";
2122
}
2223

24+
$date = (new ReflectionClass(DateTime::class))->newInstanceWithoutConstructor();
25+
$dateperiod = (new ReflectionClass(DatePeriod::class))->newInstanceWithoutConstructor();
26+
$dateinterval = (new ReflectionClass(DateInterval::class))->newInstanceWithoutConstructor();
27+
try {
28+
$dateperiod->__unserialize(['start' => $date]);
29+
} catch (Error $e) {
30+
echo get_class($e), ': ', $e->getMessage(), "\n";
31+
}
32+
33+
try {
34+
$dateperiod->__unserialize(['start' => $now, 'end' => $date]);
35+
} catch (Error $e) {
36+
echo get_class($e), ': ', $e->getMessage(), "\n";
37+
}
38+
39+
try {
40+
$dateperiod->__unserialize(['start' => $now, 'end' => $now, 'current' => $date]);
41+
} catch (Error $e) {
42+
echo get_class($e), ': ', $e->getMessage(), "\n";
43+
}
44+
45+
try {
46+
$dateperiod->__unserialize(['start' => $now, 'end' => $now, 'current' => $now, 'interval' => $dateinterval]);
47+
} catch (Error $e) {
48+
echo get_class($e), ': ', $e->getMessage(), "\n";
49+
}
50+
51+
try {
52+
$dateperiod->__unserialize([
53+
'start' => $now, 'end' => $now, 'current' => $now, 'interval' => $simpleInterval,
54+
'recurrences' => 2, 'include_start_date' => true, 'include_end_date' => true,
55+
]);
56+
echo "DatePeriod::__unserialize: SUCCESS\n";
57+
} catch (Error $e) {
58+
echo get_class($e), ': ', $e->getMessage(), "\n";
59+
}
2360
echo "OK\n";
2461
?>
2562
--EXPECT--
2663
DateObjectError: Object of type DateTimeInterface has not been correctly initialized by calling parent::__construct() in its constructor
2764
DateObjectError: Object of type DateTimeInterface has not been correctly initialized by calling parent::__construct() in its constructor
65+
Error: Invalid serialization data for DatePeriod object
66+
Error: Invalid serialization data for DatePeriod object
67+
Error: Invalid serialization data for DatePeriod object
68+
Error: Invalid serialization data for DatePeriod object
69+
DatePeriod::__unserialize: SUCCESS
2870
OK

0 commit comments

Comments
 (0)