From adc26424aa0762baeb8a3da43b9ababb14fb299c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1t=C3=A9=20Kocsis?= Date: Sat, 18 Nov 2023 22:37:11 +0100 Subject: [PATCH] Deprecate calling DatePeriod::__construct() with less than 3 arguments --- UPGRADING | 4 ++++ ext/date/php_date.c | 6 ++++++ ext/date/tests/DatePeriod_IteratorAggregate.phpt | 7 ++++++- ext/date/tests/DatePeriod_wrong_arguments.phpt | 4 +++- ext/date/tests/bug44562.phpt | 3 ++- ext/date/tests/bug54283.phpt | 2 ++ ext/date/tests/date_interval_bad_format_leak.phpt | 6 +++++- ext/date/tests/date_period_bad_iso_format.phpt | 7 ++++++- 8 files changed, 34 insertions(+), 5 deletions(-) diff --git a/UPGRADING b/UPGRADING index 28ce637881a..36590ba78e9 100644 --- a/UPGRADING +++ b/UPGRADING @@ -142,6 +142,10 @@ PHP 8.4 UPGRADE NOTES 4. Deprecated Functionality ======================================== +- Date: + . Calling DatePeriod::__construct(string $isostr, int $options = 0) is + deprecated. Use DatePeriod::createFromISO8601String() instead. + ======================================== 5. Changed Functions ======================================== diff --git a/ext/date/php_date.c b/ext/date/php_date.c index 509b09ef37d..f9695414af9 100644 --- a/ext/date/php_date.c +++ b/ext/date/php_date.c @@ -5061,6 +5061,12 @@ PHP_METHOD(DatePeriod, __construct) dpobj->current = NULL; if (isostr) { + zend_error(E_DEPRECATED, "Calling DatePeriod::__construct(string $isostr, int $options = 0) is deprecated, " + "use DatePeriod::createFromISO8601String() instead"); + if (UNEXPECTED(EG(exception))) { + RETURN_THROWS(); + } + if (!date_period_init_iso8601_string(dpobj, date_ce_date, isostr, isostr_len, options, &recurrences)) { RETURN_THROWS(); } diff --git a/ext/date/tests/DatePeriod_IteratorAggregate.phpt b/ext/date/tests/DatePeriod_IteratorAggregate.phpt index f3221822b2b..426bf7b58fe 100644 --- a/ext/date/tests/DatePeriod_IteratorAggregate.phpt +++ b/ext/date/tests/DatePeriod_IteratorAggregate.phpt @@ -58,7 +58,8 @@ foreach ($period as $i => $notDate) { } ?> ---EXPECT-- +--EXPECTF-- +Deprecated: Calling DatePeriod::__construct(string $isostr, int $options = 0) is deprecated, use DatePeriod::createFromISO8601String() instead in %s on line %d 0: 2012-07-01 1: 2012-07-08 2: 2012-07-15 @@ -79,10 +80,14 @@ foreach ($period as $i => $notDate) { 1: 2012-07-08 2: 2012-07-15 + +Deprecated: Calling DatePeriod::__construct(string $isostr, int $options = 0) is deprecated, use DatePeriod::createFromISO8601String() instead in %s on line %d 0: 2012-07-01 1: 2012-07-08 2: 2012-07-15 + +Deprecated: Calling DatePeriod::__construct(string $isostr, int $options = 0) is deprecated, use DatePeriod::createFromISO8601String() instead in %s on line %d 0: 1 1: 2 2: 3 diff --git a/ext/date/tests/DatePeriod_wrong_arguments.phpt b/ext/date/tests/DatePeriod_wrong_arguments.phpt index f1be65badbd..1d200fb096f 100644 --- a/ext/date/tests/DatePeriod_wrong_arguments.phpt +++ b/ext/date/tests/DatePeriod_wrong_arguments.phpt @@ -21,9 +21,11 @@ try { echo $e::class, ': ', $e->getMessage(), "\n"; } ?> ---EXPECT-- +--EXPECTF-- OK OK + +Deprecated: Calling DatePeriod::__construct(string $isostr, int $options = 0) is deprecated, use DatePeriod::createFromISO8601String() instead in %s on line %d OK OK TypeError: DatePeriod::__construct() accepts (DateTimeInterface, DateInterval, int [, int]), or (DateTimeInterface, DateInterval, DateTime [, int]), or (string [, int]) as arguments diff --git a/ext/date/tests/bug44562.phpt b/ext/date/tests/bug44562.phpt index dd8953faa0d..00bc1ee4f11 100644 --- a/ext/date/tests/bug44562.phpt +++ b/ext/date/tests/bug44562.phpt @@ -26,7 +26,8 @@ foreach ( $dp as $d ) } ?> ---EXPECT-- +--EXPECTF-- +Deprecated: Calling DatePeriod::__construct(string $isostr, int $options = 0) is deprecated, use DatePeriod::createFromISO8601String() instead in %s on line %d DateMalformedPeriodStringException: Unknown or bad format (2D) DateMalformedPeriodStringException: Unknown or bad format (2D) string(24) "2008-07-20T22:44:53+0200" diff --git a/ext/date/tests/bug54283.phpt b/ext/date/tests/bug54283.phpt index 8aaa1e47f72..6acf6e5c880 100644 --- a/ext/date/tests/bug54283.phpt +++ b/ext/date/tests/bug54283.phpt @@ -12,4 +12,6 @@ try { ?> --EXPECTF-- Deprecated: DatePeriod::__construct(): Passing null to parameter #1 ($start) of type string is deprecated in %s on line %d + +Deprecated: Calling DatePeriod::__construct(string $isostr, int $options = 0) is deprecated, use DatePeriod::createFromISO8601String() instead in %s on line %d string(24) "Unknown or bad format ()" diff --git a/ext/date/tests/date_interval_bad_format_leak.phpt b/ext/date/tests/date_interval_bad_format_leak.phpt index 9ce9c8d0510..010621de712 100644 --- a/ext/date/tests/date_interval_bad_format_leak.phpt +++ b/ext/date/tests/date_interval_bad_format_leak.phpt @@ -34,9 +34,13 @@ try { } ?> ---EXPECT-- +--EXPECTF-- DateMalformedIntervalStringException: Unknown or bad format (P3"D) + +Deprecated: Calling DatePeriod::__construct(string $isostr, int $options = 0) is deprecated, use DatePeriod::createFromISO8601String() instead in %s on line %d DateMalformedPeriodStringException: Unknown or bad format (P3"D) DateMalformedPeriodStringException: Unknown or bad format (P3"D) + +Deprecated: Calling DatePeriod::__construct(string $isostr, int $options = 0) is deprecated, use DatePeriod::createFromISO8601String() instead in %s on line %d DateMalformedPeriodStringException: Unknown or bad format (2008-03-01T12:00:00Z1) DateMalformedPeriodStringException: Unknown or bad format (2008-03-01T12:00:00Z1) diff --git a/ext/date/tests/date_period_bad_iso_format.phpt b/ext/date/tests/date_period_bad_iso_format.phpt index dde177e7398..144b4cce1c5 100644 --- a/ext/date/tests/date_period_bad_iso_format.phpt +++ b/ext/date/tests/date_period_bad_iso_format.phpt @@ -40,10 +40,15 @@ try { } ?> ---EXPECT-- +--EXPECTF-- +Deprecated: Calling DatePeriod::__construct(string $isostr, int $options = 0) is deprecated, use DatePeriod::createFromISO8601String() instead in %s on line %d DateMalformedPeriodStringException: DatePeriod::__construct(): ISO interval must contain a start date, "R4" given DateMalformedPeriodStringException: DatePeriod::createFromISO8601String(): ISO interval must contain a start date, "R4" given + +Deprecated: Calling DatePeriod::__construct(string $isostr, int $options = 0) is deprecated, use DatePeriod::createFromISO8601String() instead in %s on line %d DateMalformedPeriodStringException: DatePeriod::__construct(): ISO interval must contain an interval, "R4/2012-07-01T00:00:00Z" given DateMalformedPeriodStringException: DatePeriod::createFromISO8601String(): ISO interval must contain an interval, "R4/2012-07-01T00:00:00Z" given + +Deprecated: Calling DatePeriod::__construct(string $isostr, int $options = 0) is deprecated, use DatePeriod::createFromISO8601String() instead in %s on line %d DateMalformedPeriodStringException: DatePeriod::__construct(): Recurrence count must be greater than 0 DateMalformedPeriodStringException: DatePeriod::createFromISO8601String(): Recurrence count must be greater than 0