Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ PHP NEWS
. Added grapheme_strrev (Yuya Hamada)
. Passing a non-stringable object as a time zone to Intl time zone
argument handling now raises TypeError instead of Error. (Weilin Du)
. IntlBreakIterator::getLocale() now raises ValueError for invalid locale
types. (Weilin Du)

- JSON:
. Enriched JSON last error / exception message with error location.
Expand Down
3 changes: 3 additions & 0 deletions UPGRADING
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ PHP 8.6 UPGRADE NOTES
- Intl:
. Passing a non-stringable object as a time zone to Intl APIs that accept
time zone objects or strings now raises a TypeError instead of an Error.
. IntlBreakIterator::getLocale() now raises a ValueError when the type is
neither Locale::ACTUAL_LOCALE nor Locale::VALID_LOCALE instead of
returning false.

- PCNTL:
. pcntl_alarm() now raises a ValueError if the seconds argument is
Expand Down
6 changes: 2 additions & 4 deletions ext/intl/breakiterator/breakiterator_methods.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -297,11 +297,9 @@ U_CFUNC PHP_METHOD(IntlBreakIterator, getLocale)
Z_PARAM_LONG(locale_type)
ZEND_PARSE_PARAMETERS_END();

/* TODO: Change to ValueError? */
if (locale_type != ULOC_ACTUAL_LOCALE && locale_type != ULOC_VALID_LOCALE) {
intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR,
"invalid locale type");
RETURN_FALSE;
zend_argument_value_error(1, "must be either Locale::ACTUAL_LOCALE or Locale::VALID_LOCALE");
RETURN_THROWS();
}

BREAKITER_METHOD_FETCH_OBJECT;
Expand Down
25 changes: 25 additions & 0 deletions ext/intl/tests/breakiter_getLocale_error.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
--TEST--
IntlBreakIterator::getLocale(): bad arguments
--EXTENSIONS--
intl
--FILE--
<?php

$bi = IntlBreakIterator::createSentenceInstance('pt');

try {
$bi->getLocale(2);
} catch (Throwable $e) {
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
}

try {
$bi->getLocale(-1);
} catch (Throwable $e) {
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
}

?>
--EXPECT--
ValueError: IntlBreakIterator::getLocale(): Argument #1 ($type) must be either Locale::ACTUAL_LOCALE or Locale::VALID_LOCALE
ValueError: IntlBreakIterator::getLocale(): Argument #1 ($type) must be either Locale::ACTUAL_LOCALE or Locale::VALID_LOCALE
Loading