Skip to content

Fix GH-19070: setlocale($type, NULL) should not be deprecated #19071

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
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
4 changes: 2 additions & 2 deletions ext/standard/basic_functions.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -2555,8 +2555,8 @@ function nl2br(string $string, bool $use_xhtml = true): string {}
function strip_tags(string $string, array|string|null $allowed_tags = null): string {}

/**
* @param array|string $locales
* @param string $rest
* @param array|string|null $locales
* @param string|null $rest
*/
function setlocale(int $category, $locales, ...$rest): string|false {}

Expand Down
2 changes: 1 addition & 1 deletion ext/standard/basic_functions_arginfo.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 14 additions & 10 deletions ext/standard/string.c
Original file line number Diff line number Diff line change
Expand Up @@ -4937,17 +4937,18 @@ PHP_FUNCTION(setlocale)
zend_string **strings = do_alloca(sizeof(zend_string *) * num_args, use_heap);

for (uint32_t i = 0; i < num_args; i++) {
if (UNEXPECTED(Z_TYPE(args[i]) != IS_ARRAY && !zend_parse_arg_str(&args[i], &strings[i], false, i + 2))) {
if (UNEXPECTED(Z_TYPE(args[i]) != IS_ARRAY && !zend_parse_arg_str(&args[i], &strings[i], true, i + 2))) {
zend_wrong_parameter_type_error(i + 2, Z_EXPECTED_ARRAY_OR_STRING, &args[i]);
goto out;
}
}

for (uint32_t i = 0; i < num_args; i++) {
zend_string *result;
if (Z_TYPE(args[i]) == IS_ARRAY) {
zval *elem;
ZEND_HASH_FOREACH_VAL(Z_ARRVAL(args[i]), elem) {
zend_string *result = try_setlocale_zval(cat, elem);
result = try_setlocale_zval(cat, elem);
if (EG(exception)) {
goto out;
}
Expand All @@ -4956,15 +4957,18 @@ PHP_FUNCTION(setlocale)
goto out;
}
} ZEND_HASH_FOREACH_END();
continue;
} else if (Z_ISNULL(args[i])) {
result = try_setlocale_str(cat, ZSTR_EMPTY_ALLOC());
} else {
zend_string *result = try_setlocale_str(cat, strings[i]);
if (EG(exception)) {
goto out;
}
if (result) {
RETVAL_STR(result);
goto out;
}
result = try_setlocale_str(cat, strings[i]);
}
if (EG(exception)) {
goto out;
}
if (result) {
RETVAL_STR(result);
goto out;
}
}

Expand Down
3 changes: 1 addition & 2 deletions ext/standard/tests/strings/gh18823_weak.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,5 @@ try {
echo $e->getMessage(), "\n";
}
?>
--EXPECTF--
Deprecated: setlocale(): Passing null to parameter #2 ($locales) of type string is deprecated in %s on line %d
--EXPECT--
no
8 changes: 8 additions & 0 deletions ext/standard/tests/strings/gh19070.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
--TEST--
GH-19070 (setlocale($type, NULL) should not be deprecated)
--FILE--
<?php
var_dump(setlocale(LC_ALL, null));
?>
--EXPECTF--
string(%d) "%s"