Skip to content

Commit c4183fb

Browse files
committed
Fix GH-19070: setlocale($type, NULL) should not be deprecated
This restores the old behaviour. Closes GH-19071.
1 parent 0d584c3 commit c4183fb

File tree

6 files changed

+28
-15
lines changed

6 files changed

+28
-15
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ PHP NEWS
88

99
- Standard:
1010
. Optimized pack(). (nielsdos, divinity76)
11+
. Fixed bug GH-19070 (setlocale($type, NULL) should not be deprecated).
12+
(nielsdos)
1113

1214
- URI:
1315
. Return the singleton UrlValidationErrorType instances from Uri\WhatWg\Url

ext/standard/basic_functions.stub.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2555,8 +2555,8 @@ function nl2br(string $string, bool $use_xhtml = true): string {}
25552555
function strip_tags(string $string, array|string|null $allowed_tags = null): string {}
25562556

25572557
/**
2558-
* @param array|string $locales
2559-
* @param string $rest
2558+
* @param array|string|null $locales
2559+
* @param string|null $rest
25602560
*/
25612561
function setlocale(int $category, $locales, ...$rest): string|false {}
25622562

ext/standard/basic_functions_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/standard/string.c

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4937,17 +4937,18 @@ PHP_FUNCTION(setlocale)
49374937
zend_string **strings = do_alloca(sizeof(zend_string *) * num_args, use_heap);
49384938

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

49464946
for (uint32_t i = 0; i < num_args; i++) {
4947+
zend_string *result;
49474948
if (Z_TYPE(args[i]) == IS_ARRAY) {
49484949
zval *elem;
49494950
ZEND_HASH_FOREACH_VAL(Z_ARRVAL(args[i]), elem) {
4950-
zend_string *result = try_setlocale_zval(cat, elem);
4951+
result = try_setlocale_zval(cat, elem);
49514952
if (EG(exception)) {
49524953
goto out;
49534954
}
@@ -4956,15 +4957,18 @@ PHP_FUNCTION(setlocale)
49564957
goto out;
49574958
}
49584959
} ZEND_HASH_FOREACH_END();
4960+
continue;
4961+
} else if (Z_ISNULL(args[i])) {
4962+
result = try_setlocale_str(cat, ZSTR_EMPTY_ALLOC());
49594963
} else {
4960-
zend_string *result = try_setlocale_str(cat, strings[i]);
4961-
if (EG(exception)) {
4962-
goto out;
4963-
}
4964-
if (result) {
4965-
RETVAL_STR(result);
4966-
goto out;
4967-
}
4964+
result = try_setlocale_str(cat, strings[i]);
4965+
}
4966+
if (EG(exception)) {
4967+
goto out;
4968+
}
4969+
if (result) {
4970+
RETVAL_STR(result);
4971+
goto out;
49684972
}
49694973
}
49704974

ext/standard/tests/strings/gh18823_weak.phpt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,5 @@ try {
2727
echo $e->getMessage(), "\n";
2828
}
2929
?>
30-
--EXPECTF--
31-
Deprecated: setlocale(): Passing null to parameter #2 ($locales) of type string is deprecated in %s on line %d
30+
--EXPECT--
3231
no
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
--TEST--
2+
GH-19070 (setlocale($type, NULL) should not be deprecated)
3+
--FILE--
4+
<?php
5+
var_dump(setlocale(LC_ALL, null));
6+
?>
7+
--EXPECTF--
8+
string(%d) "%s"

0 commit comments

Comments
 (0)