Skip to content

Commit b860837

Browse files
committed
Merge branch 'PHP-8.5'
* PHP-8.5: Fix GH-20936: DatePeriod::__set_state() cannot handle null start
2 parents 345bf38 + 34a341e commit b860837

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

ext/date/php_date.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5747,7 +5747,7 @@ static bool php_date_period_initialize_from_hash(php_period_obj *period_obj, con
57475747
php_date_obj *date_obj;
57485748
date_obj = Z_PHPDATE_P(ht_entry);
57495749

5750-
if (!date_obj->time) {
5750+
if (!date_obj->time || !period_obj->start_ce) {
57515751
return false;
57525752
}
57535753

@@ -5768,7 +5768,7 @@ static bool php_date_period_initialize_from_hash(php_period_obj *period_obj, con
57685768
php_date_obj *date_obj;
57695769
date_obj = Z_PHPDATE_P(ht_entry);
57705770

5771-
if (!date_obj->time) {
5771+
if (!date_obj->time || !period_obj->start_ce) {
57725772
return false;
57735773
}
57745774

ext/date/tests/gh20936.phpt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
--TEST--
2+
GH-20936 (DatePeriod::__set_state() cannot handle null start)
3+
--FILE--
4+
<?php
5+
$end = new DateTime('2022-07-16', new DateTimeZone('UTC'));
6+
$interval = new DateInterval('P2D');
7+
try {
8+
DatePeriod::__set_state(['start' => null, 'end' => $end, 'current' => null, 'interval' => $interval, 'recurrences' => 2, 'include_start_date' => false, 'include_end_date' => true]);
9+
} catch (Throwable $e) {
10+
echo $e::class, ": ", $e->getMessage(), "\n";
11+
}
12+
?>
13+
--EXPECT--
14+
Error: Invalid serialization data for DatePeriod object

0 commit comments

Comments
 (0)