Skip to content

Commit f4df37a

Browse files
committed
Deprecate calling IntlCalendar::set() with more than 2 arguments and intlcal_set()
1 parent adc2642 commit f4df37a

11 files changed

+40
-11
lines changed

UPGRADING

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,10 @@ PHP 8.4 UPGRADE NOTES
146146
. Calling DatePeriod::__construct(string $isostr, int $options = 0) is
147147
deprecated. Use DatePeriod::createFromISO8601String() instead.
148148

149+
- Intl:
150+
. Calling intlcal_set() as well as calling IntlCalendar::set() with
151+
more than 2 arguments is deprecated. Use either IntlCalendar::setDate()
152+
or IntlCalendar::setDateTime() instead.
149153
========================================
150154
5. Changed Functions
151155
========================================

ext/intl/calendar/calendar.stub.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ public function isSet(int $field): bool {}
316316

317317
/**
318318
* @return true
319-
* @alias intlcal_set
319+
* @implementation-alias intlcal_set
320320
*/
321321
public function set(int $year, int $month, int $dayOfMonth = UNKNOWN, int $hour = UNKNOWN, int $minute = UNKNOWN, int $second = UNKNOWN) {} // TODO make return type void
322322

ext/intl/calendar/calendar_arginfo.h

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ext/intl/calendar/calendar_methods.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,14 @@ U_CFUNC PHP_FUNCTION(intlcal_set)
377377

378378
int arg_num = ZEND_NUM_ARGS() - (object ? 0 : 1);
379379

380+
if (object && arg_num > 2) {
381+
zend_error(E_DEPRECATED, "Calling IntlCalendar::set() with more than 2 arguments is deprecated, "
382+
"use either IntlCalendar::setDate() or IntlCalendar::setDateTime() instead");
383+
if (UNEXPECTED(EG(exception))) {
384+
RETURN_THROWS();
385+
}
386+
}
387+
380388
if (zend_parse_method_parameters(
381389
ZEND_NUM_ARGS(), object, "Oll|llll",
382390
&object, Calendar_ce_ptr, &args[0], &args[1], &args[2], &args[3], &args[4], &args[5]

ext/intl/php_intl.stub.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ function intlcal_after(IntlCalendar $calendar, IntlCalendar $other): bool {}
201201

202202
function intlcal_before(IntlCalendar $calendar, IntlCalendar $other): bool {}
203203

204+
/** @deprecated */
204205
function intlcal_set(IntlCalendar $calendar, int $year, int $month, int $dayOfMonth = UNKNOWN, int $hour = UNKNOWN, int $minute = UNKNOWN, int $second = UNKNOWN): true {}
205206

206207
/** @param int|bool $value */

ext/intl/php_intl_arginfo.h

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ext/intl/tests/calendar_isSet_empty_time.phpt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ var_dump($intlcal->get(IntlCalendar::FIELD_MINUTE));
2121
var_dump($intlcal->isSet(IntlCalendar::FIELD_SECOND));
2222

2323
?>
24-
--EXPECT--
24+
--EXPECTF--
25+
Deprecated: Calling IntlCalendar::set() with more than 2 arguments is deprecated, use either IntlCalendar::setDate() or IntlCalendar::setDateTime() instead in %s on line %d
2526
bool(false)
2627
int(58)
2728
bool(true)

ext/intl/tests/calendar_set_basic.phpt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@ var_dump(intlcal_set($intlcal, IntlCalendar::FIELD_DAY_OF_MONTH, 3));
1616
var_dump($intlcal->get(IntlCalendar::FIELD_DAY_OF_MONTH));
1717

1818
?>
19-
--EXPECT--
19+
--EXPECTF--
2020
bool(true)
2121
int(2)
22+
23+
Deprecated: Function intlcal_set() is deprecated in %s on line %d
2224
bool(true)
23-
int(3)
25+
int(3)

ext/intl/tests/calendar_set_error.phpt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,16 @@ try {
4040
echo $e->getMessage() . \PHP_EOL;
4141
}
4242
?>
43-
--EXPECT--
43+
--EXPECTF--
44+
Deprecated: Calling IntlCalendar::set() with more than 2 arguments is deprecated, use either IntlCalendar::setDate() or IntlCalendar::setDateTime() instead in %s on line %d
4445
IntlCalendar::set() expects at most 6 arguments, 7 given
46+
47+
Deprecated: Calling IntlCalendar::set() with more than 2 arguments is deprecated, use either IntlCalendar::setDate() or IntlCalendar::setDateTime() instead in %s on line %d
4548
IntlCalendar::set() has no variant with exactly 4 parameters
4649
IntlCalendar::set(): Argument #1 ($year) must be a valid field
50+
51+
Deprecated: Function intlcal_set() is deprecated in %s on line %d
4752
intlcal_set(): Argument #2 ($year) must be a valid field
53+
54+
Deprecated: Function intlcal_set() is deprecated in %s on line %d
4855
intlcal_set(): Argument #1 ($calendar) must be of type IntlCalendar, int given

ext/intl/tests/calendar_set_variation1.phpt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,18 @@ var_dump($intlcal->getTime(),
2525
strtotime('2012-02-29 23:58:31 +0000') * 1000.);
2626

2727
?>
28-
--EXPECT--
28+
--EXPECTF--
29+
Deprecated: Calling IntlCalendar::set() with more than 2 arguments is deprecated, use either IntlCalendar::setDate() or IntlCalendar::setDateTime() instead in %s on line %d
2930
bool(true)
3031
float(1330473600000)
3132
float(1330473600000)
33+
34+
Deprecated: Calling IntlCalendar::set() with more than 2 arguments is deprecated, use either IntlCalendar::setDate() or IntlCalendar::setDateTime() instead in %s on line %d
3235
bool(true)
3336
float(1330559880000)
3437
float(1330559880000)
38+
39+
Deprecated: Calling IntlCalendar::set() with more than 2 arguments is deprecated, use either IntlCalendar::setDate() or IntlCalendar::setDateTime() instead in %s on line %d
3540
bool(true)
3641
float(1330559911000)
37-
float(1330559911000)
42+
float(1330559911000)

ext/intl/tests/calendar_toDateTime_basic.phpt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ $dt = $cal->toDateTime();
1414

1515
var_dump($dt->format("c"), $dt->getTimeZone()->getName());
1616
?>
17-
--EXPECT--
17+
--EXPECTF--
18+
Deprecated: Calling IntlGregorianCalendar::__construct() with more than 2 arguments is deprecated in %s on line %d
1819
string(25) "2012-05-17T17:35:36+01:00"
1920
string(13) "Europe/Lisbon"

0 commit comments

Comments
 (0)