Skip to content

Commit 19cafa6

Browse files
committed
feedback
1 parent c9928ef commit 19cafa6

4 files changed

Lines changed: 21 additions & 9 deletions

File tree

NEWS

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ PHP NEWS
5252
- Standard:
5353
. Fixed setlocale() to reject locale names containing NUL bytes instead of
5454
silently truncating them, and to reject arrays passed after the $locales
55-
argument. (Weilin Du)
55+
argument or additional arguments passed after an array $locales argument.
56+
(Weilin Du)
5657

5758
- Streams:
5859
. Added a new IO copy API used by php_stream_copy_to_stream_ex() that

UPGRADING

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,9 @@ PHP 8.6 UPGRADE NOTES
204204
. setlocale() now raises a ValueError when a locale name contains NUL bytes,
205205
instead of silently truncating it.
206206
Arrays are now accepted only for the $locales argument. Passing an array as
207-
a later variadic locale argument now throws a TypeError; if $locales is an
208-
array, only that array is processed.
207+
a later variadic locale argument now throws a TypeError. Passing any
208+
additional locale arguments when $locales is an array now throws an
209+
ArgumentCountError.
209210
. linkinfo() now raises a ValueError when the $path argument is empty.
210211
. pathinfo() now raises a ValueError when an invalid $flag argument value is
211212
passed.

ext/standard/string.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4903,14 +4903,14 @@ static zend_string *try_setlocale_str(zend_long cat, zend_string *loc) {
49034903
return zend_string_init(retval, strlen(retval), 0);
49044904
}
49054905

4906-
static zend_string *try_setlocale_zval(zend_long cat, zval *loc_zv, uint32_t arg_num) {
4906+
static zend_string *try_setlocale_zval(zend_long cat, zval *loc_zv) {
49074907
zend_string *tmp_loc_str;
49084908
zend_string *loc_str = zval_try_get_tmp_string(loc_zv, &tmp_loc_str);
49094909
if (UNEXPECTED(loc_str == NULL)) {
49104910
return NULL;
49114911
}
49124912
if (zend_str_has_nul_byte(loc_str)) {
4913-
zend_argument_value_error(arg_num, "must not contain any null bytes");
4913+
zend_argument_value_error(2, "must not contain any null bytes");
49144914
zend_tmp_string_release(tmp_loc_str);
49154915
return NULL;
49164916
}
@@ -4940,6 +4940,12 @@ PHP_FUNCTION(setlocale)
49404940
zend_wrong_parameter_type_error(i + 2, Z_EXPECTED_STRING_OR_NULL, &args[i]);
49414941
goto out;
49424942
}
4943+
if (UNEXPECTED(num_args > 1)) {
4944+
zend_argument_count_error(
4945+
"setlocale() expects exactly 2 arguments when argument #2 ($locales) is an array, %d given",
4946+
ZEND_NUM_ARGS());
4947+
goto out;
4948+
}
49434949
num_args = 1;
49444950
break;
49454951
}
@@ -4959,7 +4965,7 @@ PHP_FUNCTION(setlocale)
49594965
if (Z_TYPE(args[i]) == IS_ARRAY) {
49604966
zval *elem;
49614967
ZEND_HASH_FOREACH_VAL(Z_ARRVAL(args[i]), elem) {
4962-
result = try_setlocale_zval(cat, elem, i + 2);
4968+
result = try_setlocale_zval(cat, elem);
49634969
if (EG(exception)) {
49644970
goto out;
49654971
}

ext/standard/tests/strings/setlocale_null_byte.phpt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,17 @@ try {
4444
echo $e::class, ": ", $e->getMessage(), \PHP_EOL;
4545
}
4646

47-
var_dump(setlocale(LC_ALL, [], new NullByteStringable()));
47+
try {
48+
var_dump(setlocale(LC_ALL, [], new NullByteStringable()));
49+
} catch (ArgumentCountError $e) {
50+
echo $e::class, ": ", $e->getMessage(), \PHP_EOL;
51+
}
4852
?>
4953
--EXPECT--
5054
ValueError: setlocale(): Argument #2 ($locales) must not contain any null bytes
5155
ValueError: setlocale(): Argument #2 ($locales) must not contain any null bytes
5256
ValueError: setlocale(): Argument #2 ($locales) must not contain any null bytes
5357
ValueError: setlocale(): Argument #2 ($locales) must not contain any null bytes
54-
TypeError: setlocale(): Argument #3 must be of type ?string, array given
58+
TypeError: setlocale(): Argument #3 must be of type array|string|null, int given
5559
ValueError: setlocale(): Argument #3 must not contain any null bytes
56-
bool(false)
60+
ArgumentCountError: setlocale() expects exactly 2 arguments when argument #2 ($locales) is an array, 3 given

0 commit comments

Comments
 (0)