Deprecate calling IntlCalendar::set() with more than 2 arguments and intlcal_set()

This commit is contained in:
Máté Kocsis 2023-11-18 22:55:52 +01:00
parent adc26424aa
commit f4df37af3d
11 changed files with 40 additions and 11 deletions

View file

@ -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
========================================

View file

@ -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

View file

@ -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()

View file

@ -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]

View file

@ -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 */

View file

@ -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)

View file

@ -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)

View file

@ -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)

View file

@ -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

View file

@ -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)

View file

@ -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"