From 67effbd5753f8bf89ce421f5f4eed49d1a2bf1ae Mon Sep 17 00:00:00 2001 From: Niels Dossche <7771979+ndossche@users.noreply.github.com> Date: Wed, 14 Jan 2026 18:38:37 +0100 Subject: [PATCH] Fix GH-20936: DatePeriod::__set_state() cannot handle null start The "current" and "end" field also rely on start_ce, which is set by "start". Therefore, if "current" or "end" are provided, so must "start" be provided. --- ext/date/php_date.c | 4 ++-- ext/date/tests/gh20936.phpt | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 ext/date/tests/gh20936.phpt diff --git a/ext/date/php_date.c b/ext/date/php_date.c index 6d0f0428f08dd..a67a58bcf9232 100644 --- a/ext/date/php_date.c +++ b/ext/date/php_date.c @@ -5811,7 +5811,7 @@ static bool php_date_period_initialize_from_hash(php_period_obj *period_obj, Has php_date_obj *date_obj; date_obj = Z_PHPDATE_P(ht_entry); - if (!date_obj->time) { + if (!date_obj->time || !period_obj->start_ce) { return 0; } @@ -5832,7 +5832,7 @@ static bool php_date_period_initialize_from_hash(php_period_obj *period_obj, Has php_date_obj *date_obj; date_obj = Z_PHPDATE_P(ht_entry); - if (!date_obj->time) { + if (!date_obj->time || !period_obj->start_ce) { return 0; } diff --git a/ext/date/tests/gh20936.phpt b/ext/date/tests/gh20936.phpt new file mode 100644 index 0000000000000..e6a525dd4583e --- /dev/null +++ b/ext/date/tests/gh20936.phpt @@ -0,0 +1,14 @@ +--TEST-- +GH-20936 (DatePeriod::__set_state() cannot handle null start) +--FILE-- + null, 'end' => $end, 'current' => null, 'interval' => $interval, 'recurrences' => 2, 'include_start_date' => false, 'include_end_date' => true]); +} catch (Throwable $e) { + echo $e::class, ": ", $e->getMessage(), "\n"; +} +?> +--EXPECT-- +Error: Invalid serialization data for DatePeriod object