From f4df37af3d1cecc23d9ce2adb8b865c9e4ac4012 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1t=C3=A9=20Kocsis?= Date: Sat, 18 Nov 2023 22:55:52 +0100 Subject: [PATCH] Deprecate calling IntlCalendar::set() with more than 2 arguments and intlcal_set() --- UPGRADING | 4 ++++ ext/intl/calendar/calendar.stub.php | 2 +- ext/intl/calendar/calendar_arginfo.h | 2 +- ext/intl/calendar/calendar_methods.cpp | 8 ++++++++ ext/intl/php_intl.stub.php | 1 + ext/intl/php_intl_arginfo.h | 4 ++-- ext/intl/tests/calendar_isSet_empty_time.phpt | 3 ++- ext/intl/tests/calendar_set_basic.phpt | 6 ++++-- ext/intl/tests/calendar_set_error.phpt | 9 ++++++++- ext/intl/tests/calendar_set_variation1.phpt | 9 +++++++-- ext/intl/tests/calendar_toDateTime_basic.phpt | 3 ++- 11 files changed, 40 insertions(+), 11 deletions(-) diff --git a/UPGRADING b/UPGRADING index 36590ba78e9..7f893882aff 100644 --- a/UPGRADING +++ b/UPGRADING @@ -146,6 +146,10 @@ PHP 8.4 UPGRADE NOTES . Calling DatePeriod::__construct(string $isostr, int $options = 0) is deprecated. Use DatePeriod::createFromISO8601String() instead. +- Intl: + . Calling intlcal_set() as well as calling IntlCalendar::set() with + more than 2 arguments is deprecated. Use either IntlCalendar::setDate() + or IntlCalendar::setDateTime() instead. ======================================== 5. Changed Functions ======================================== diff --git a/ext/intl/calendar/calendar.stub.php b/ext/intl/calendar/calendar.stub.php index 7a1343931c2..828e869f0ee 100644 --- a/ext/intl/calendar/calendar.stub.php +++ b/ext/intl/calendar/calendar.stub.php @@ -316,7 +316,7 @@ class IntlCalendar /** * @return true - * @alias intlcal_set + * @implementation-alias intlcal_set */ public function set(int $year, int $month, int $dayOfMonth = UNKNOWN, int $hour = UNKNOWN, int $minute = UNKNOWN, int $second = UNKNOWN) {} // TODO make return type void diff --git a/ext/intl/calendar/calendar_arginfo.h b/ext/intl/calendar/calendar_arginfo.h index 803771f6a12..9c57d5b0d94 100644 --- a/ext/intl/calendar/calendar_arginfo.h +++ b/ext/intl/calendar/calendar_arginfo.h @@ -1,5 +1,5 @@ /* This is a generated file, edit the .stub.php file instead. - * Stub hash: cbb02e588a6954e7e92556e7ce656ea36a05cf3f */ + * Stub hash: dbd7f8dd82cfdca04988aa791523b29b564347e0 */ ZEND_BEGIN_ARG_INFO_EX(arginfo_class_IntlCalendar___construct, 0, 0, 0) ZEND_END_ARG_INFO() diff --git a/ext/intl/calendar/calendar_methods.cpp b/ext/intl/calendar/calendar_methods.cpp index 506f3487f51..d6801c4f646 100644 --- a/ext/intl/calendar/calendar_methods.cpp +++ b/ext/intl/calendar/calendar_methods.cpp @@ -377,6 +377,14 @@ U_CFUNC PHP_FUNCTION(intlcal_set) int arg_num = ZEND_NUM_ARGS() - (object ? 0 : 1); + if (object && arg_num > 2) { + zend_error(E_DEPRECATED, "Calling IntlCalendar::set() with more than 2 arguments is deprecated, " + "use either IntlCalendar::setDate() or IntlCalendar::setDateTime() instead"); + if (UNEXPECTED(EG(exception))) { + RETURN_THROWS(); + } + } + if (zend_parse_method_parameters( ZEND_NUM_ARGS(), object, "Oll|llll", &object, Calendar_ce_ptr, &args[0], &args[1], &args[2], &args[3], &args[4], &args[5] diff --git a/ext/intl/php_intl.stub.php b/ext/intl/php_intl.stub.php index eab42fcc0ff..8eb1d977930 100644 --- a/ext/intl/php_intl.stub.php +++ b/ext/intl/php_intl.stub.php @@ -201,6 +201,7 @@ function intlcal_after(IntlCalendar $calendar, IntlCalendar $other): bool {} function intlcal_before(IntlCalendar $calendar, IntlCalendar $other): bool {} +/** @deprecated */ function intlcal_set(IntlCalendar $calendar, int $year, int $month, int $dayOfMonth = UNKNOWN, int $hour = UNKNOWN, int $minute = UNKNOWN, int $second = UNKNOWN): true {} /** @param int|bool $value */ diff --git a/ext/intl/php_intl_arginfo.h b/ext/intl/php_intl_arginfo.h index c05ecb7b249..86899ecb3e7 100644 --- a/ext/intl/php_intl_arginfo.h +++ b/ext/intl/php_intl_arginfo.h @@ -1,5 +1,5 @@ /* This is a generated file, edit the .stub.php file instead. - * Stub hash: c32e74bddb55455f69083a302bcaf52f654b1293 */ + * Stub hash: 9b71cd87f05bb7644a98c9855afba4742ac6203c */ ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_intlcal_create_instance, 0, 0, IntlCalendar, 1) ZEND_ARG_INFO_WITH_DEFAULT_VALUE(0, timezone, "null") @@ -987,7 +987,7 @@ static const zend_function_entry ext_functions[] = { ZEND_FE(intlcal_set_time_zone, arginfo_intlcal_set_time_zone) ZEND_FE(intlcal_after, arginfo_intlcal_after) ZEND_FE(intlcal_before, arginfo_intlcal_before) - ZEND_FE(intlcal_set, arginfo_intlcal_set) + ZEND_DEP_FE(intlcal_set, arginfo_intlcal_set) ZEND_FE(intlcal_roll, arginfo_intlcal_roll) ZEND_FE(intlcal_clear, arginfo_intlcal_clear) ZEND_FE(intlcal_field_difference, arginfo_intlcal_field_difference) diff --git a/ext/intl/tests/calendar_isSet_empty_time.phpt b/ext/intl/tests/calendar_isSet_empty_time.phpt index 0fbecd72b63..533baffe49f 100644 --- a/ext/intl/tests/calendar_isSet_empty_time.phpt +++ b/ext/intl/tests/calendar_isSet_empty_time.phpt @@ -21,7 +21,8 @@ var_dump($intlcal->get(IntlCalendar::FIELD_MINUTE)); var_dump($intlcal->isSet(IntlCalendar::FIELD_SECOND)); ?> ---EXPECT-- +--EXPECTF-- +Deprecated: Calling IntlCalendar::set() with more than 2 arguments is deprecated, use either IntlCalendar::setDate() or IntlCalendar::setDateTime() instead in %s on line %d bool(false) int(58) bool(true) diff --git a/ext/intl/tests/calendar_set_basic.phpt b/ext/intl/tests/calendar_set_basic.phpt index b9f4b561b52..56017f2bf55 100644 --- a/ext/intl/tests/calendar_set_basic.phpt +++ b/ext/intl/tests/calendar_set_basic.phpt @@ -16,8 +16,10 @@ var_dump(intlcal_set($intlcal, IntlCalendar::FIELD_DAY_OF_MONTH, 3)); var_dump($intlcal->get(IntlCalendar::FIELD_DAY_OF_MONTH)); ?> ---EXPECT-- +--EXPECTF-- bool(true) int(2) + +Deprecated: Function intlcal_set() is deprecated in %s on line %d bool(true) -int(3) \ No newline at end of file +int(3) diff --git a/ext/intl/tests/calendar_set_error.phpt b/ext/intl/tests/calendar_set_error.phpt index 128f4d12692..d91c9449ac4 100644 --- a/ext/intl/tests/calendar_set_error.phpt +++ b/ext/intl/tests/calendar_set_error.phpt @@ -40,9 +40,16 @@ try { echo $e->getMessage() . \PHP_EOL; } ?> ---EXPECT-- +--EXPECTF-- +Deprecated: Calling IntlCalendar::set() with more than 2 arguments is deprecated, use either IntlCalendar::setDate() or IntlCalendar::setDateTime() instead in %s on line %d IntlCalendar::set() expects at most 6 arguments, 7 given + +Deprecated: Calling IntlCalendar::set() with more than 2 arguments is deprecated, use either IntlCalendar::setDate() or IntlCalendar::setDateTime() instead in %s on line %d IntlCalendar::set() has no variant with exactly 4 parameters IntlCalendar::set(): Argument #1 ($year) must be a valid field + +Deprecated: Function intlcal_set() is deprecated in %s on line %d intlcal_set(): Argument #2 ($year) must be a valid field + +Deprecated: Function intlcal_set() is deprecated in %s on line %d intlcal_set(): Argument #1 ($calendar) must be of type IntlCalendar, int given diff --git a/ext/intl/tests/calendar_set_variation1.phpt b/ext/intl/tests/calendar_set_variation1.phpt index dae639e298e..520c9094873 100644 --- a/ext/intl/tests/calendar_set_variation1.phpt +++ b/ext/intl/tests/calendar_set_variation1.phpt @@ -25,13 +25,18 @@ var_dump($intlcal->getTime(), strtotime('2012-02-29 23:58:31 +0000') * 1000.); ?> ---EXPECT-- +--EXPECTF-- +Deprecated: Calling IntlCalendar::set() with more than 2 arguments is deprecated, use either IntlCalendar::setDate() or IntlCalendar::setDateTime() instead in %s on line %d bool(true) float(1330473600000) float(1330473600000) + +Deprecated: Calling IntlCalendar::set() with more than 2 arguments is deprecated, use either IntlCalendar::setDate() or IntlCalendar::setDateTime() instead in %s on line %d bool(true) float(1330559880000) float(1330559880000) + +Deprecated: Calling IntlCalendar::set() with more than 2 arguments is deprecated, use either IntlCalendar::setDate() or IntlCalendar::setDateTime() instead in %s on line %d bool(true) float(1330559911000) -float(1330559911000) \ No newline at end of file +float(1330559911000) diff --git a/ext/intl/tests/calendar_toDateTime_basic.phpt b/ext/intl/tests/calendar_toDateTime_basic.phpt index 89a848dbb8c..2f125672d50 100644 --- a/ext/intl/tests/calendar_toDateTime_basic.phpt +++ b/ext/intl/tests/calendar_toDateTime_basic.phpt @@ -14,6 +14,7 @@ $dt = $cal->toDateTime(); var_dump($dt->format("c"), $dt->getTimeZone()->getName()); ?> ---EXPECT-- +--EXPECTF-- +Deprecated: Calling IntlGregorianCalendar::__construct() with more than 2 arguments is deprecated in %s on line %d string(25) "2012-05-17T17:35:36+01:00" string(13) "Europe/Lisbon"