Skip to content

Commit

Permalink
Deprecate IntlCalendar::roll() with bool argument
Browse files Browse the repository at this point in the history
Pass 1 instead of true and -1 instead of false.

Part of https://wiki.php.net/rfc/deprecations_php_8_1.
  • Loading branch information
nikic committed Jul 8, 2021
1 parent 92f6e21 commit 1c50784
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 4 deletions.
5 changes: 5 additions & 0 deletions UPGRADING
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,11 @@ PHP 8.1 UPGRADE NOTES
favor of date_sun_info().
RFC: https://wiki.php.net/rfc/deprecations_php_8_1

- Intl:
. Calling IntlCalendar::roll() with bool argument is deprecated. Pass 1 and -1
instead of true and false respectively.
RFC: https://wiki.php.net/rfc/deprecations_php_8_1

- Mbstring:
. Calling mb_check_encoding() without an argument is deprecated.
RFC: https://wiki.php.net/rfc/deprecations_php_8_1
Expand Down
1 change: 1 addition & 0 deletions ext/intl/calendar/calendar_methods.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,7 @@ U_CFUNC PHP_FUNCTION(intlcal_roll)

if (Z_TYPE_P(zvalue) == IS_FALSE || Z_TYPE_P(zvalue) == IS_TRUE) {
value = Z_TYPE_P(zvalue) == IS_TRUE ? 1 : -1;
php_error_docref(NULL, E_DEPRECATED, "Passing bool is deprecated, use 1 or -1 instead");
} else {
value = zval_get_long(zvalue);
ZEND_VALUE_ERROR_OUT_OF_BOUND_VALUE(value, 3);
Expand Down
4 changes: 2 additions & 2 deletions ext/intl/tests/calendar_isEquivalentTo_basic.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ $intlcal1 = IntlCalendar::createInstance('Europe/Amsterdam');
$intlcal2 = IntlCalendar::createInstance('Europe/Lisbon');
$intlcal3 = IntlCalendar::createInstance('Europe/Amsterdam', "nl_NL@calendar=islamic");
$intlcal4 = IntlCalendar::createInstance('Europe/Amsterdam');
$intlcal4->roll(IntlCalendar::FIELD_MONTH, true);
$intlcal4->roll(IntlCalendar::FIELD_MONTH, 1);

var_dump(
"1 - 1",
Expand All @@ -33,4 +33,4 @@ bool(false)
string(5) "1 - 3"
bool(false)
string(5) "1 - 4"
bool(true)
bool(true)
7 changes: 5 additions & 2 deletions ext/intl/tests/calendar_roll_variation1.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,13 @@ var_dump($intlcal->get(IntlCalendar::FIELD_MONTH)); //1 (Feb)
var_dump($intlcal->get(IntlCalendar::FIELD_DAY_OF_MONTH)); //28

?>
--EXPECT--
--EXPECTF--
Deprecated: IntlCalendar::roll(): Passing bool is deprecated, use 1 or -1 instead in %s on line %d
bool(true)
int(1)
int(29)

Deprecated: intlcal_roll(): Passing bool is deprecated, use 1 or -1 instead in %s on line %d
bool(true)
int(1)
int(28)
int(28)

0 comments on commit 1c50784

Please sign in to comment.