[php-src] master: Merge branch 'PHP-8.5' into PHP-8.6
| From: | Weilin Du | Date: | Tue, 17 Nov 2026 11:26:46 +0000 |
| Subject: | [php-src] master: Merge branch 'PHP-8.5' into PHP-8.6 | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-143761@lists.php.net to get a copy of this message | ||
Author: Weilin Du (LamentXU123)
Date: 2026-11-17T19:22:40+08:00
Commit: https://github.com/php/php-src/commit/3fa233451aad86d4995948c99041b5ccdf364ea5
Raw diff: https://github.com/php/php-src/commit/3fa233451aad86d4995948c99041b5ccdf364ea5.diff
Merge branch 'PHP-8.5' into PHP-8.6
* PHP-8.5:
ext/intl: Fix Locale::lookup() fallback for empty language tags (#25462)
Changed paths:
A ext/intl/tests/locale_lookup_empty_language_tags.phpt
M NEWS
M ext/intl/locale/locale_methods.cpp
Diff:
diff --git a/NEWS b/NEWS
index b032c454417d..84e70e056c1a 100644
--- a/NEWS
+++ b/NEWS
@@ -64,6 +64,8 @@ PHP NEWS
. Fixed NumberFormatter::getSymbol(), setSymbol(), getAttribute() and
setAttribute() accepting out-of-range values that truncate to a valid one.
(Jorg Sowa)
+ . Fixed Locale::lookup() ignoring the default locale when the language tag
+ list is empty. (Weilin Du)
- JSON:
. Fixed json_decode() and json_validate() error messages. (lacatoire)
diff --git a/ext/intl/locale/locale_methods.cpp b/ext/intl/locale/locale_methods.cpp
index 911abfdc5c11..4febdf0f9ec1 100644
--- a/ext/intl/locale/locale_methods.cpp
+++ b/ext/intl/locale/locale_methods.cpp
@@ -1635,6 +1635,9 @@ PHP_INTL_FUNCTION_WITH_ERROR_RESET(locale_lookup)
INTL_CHECK_LOCALE_LEN(loc_range_len);
if( !hash_arr || zend_hash_num_elements( hash_arr ) == 0 ) {
+ if (fallback_loc_str) {
+ RETURN_STR_COPY(fallback_loc_str);
+ }
RETURN_EMPTY_STRING();
}
diff --git a/ext/intl/tests/locale_lookup_empty_language_tags.phpt
b/ext/intl/tests/locale_lookup_empty_language_tags.phpt
new file mode 100644
index 000000000000..b0bb2d1e6993
--- /dev/null
+++ b/ext/intl/tests/locale_lookup_empty_language_tags.phpt
@@ -0,0 +1,42 @@
+--TEST--
+Locale::lookup() honors the default locale for an empty language tag list
+--EXTENSIONS--
+intl
+--FILE--
+<?php
+foreach (['locale_lookup', [Locale::class, 'lookup']] as $lookup) {
+ foreach ([false, true] as $canonicalize) {
+ var_dump($lookup([], 'fr_FR', $canonicalize, 'en-US'));
+ var_dump($lookup([], '', $canonicalize, 'en-US'));
+ var_dump($lookup([], 'fr_FR', $canonicalize, ''));
+ var_dump($lookup([], 'fr_FR', $canonicalize, null));
+ var_dump($lookup([], 'fr_FR', $canonicalize));
+ var_dump(intl_get_error_code());
+ }
+}
+?>
+--EXPECT--
+string(5) "en-US"
+string(5) "en-US"
+string(0) ""
+string(0) ""
+string(0) ""
+int(0)
+string(5) "en-US"
+string(5) "en-US"
+string(0) ""
+string(0) ""
+string(0) ""
+int(0)
+string(5) "en-US"
+string(5) "en-US"
+string(0) ""
+string(0) ""
+string(0) ""
+int(0)
+string(5) "en-US"
+string(5) "en-US"
+string(0) ""
+string(0) ""
+string(0) ""
+int(0)