[php-src] PHP-8.6: Merge branch 'PHP-8.4' into PHP-8.5
| From: | Weilin Du | Date: | Tue, 17 Nov 2026 11:26:45 +0000 |
| Subject: | [php-src] PHP-8.6: Merge branch 'PHP-8.4' into PHP-8.5 | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-143762@lists.php.net to get a copy of this message | ||
Author: Weilin Du (LamentXU123)
Date: 2026-11-17T19:22:16+08:00
Commit: https://github.com/php/php-src/commit/6f91fcc866648eb40a4fa2846754d0adcff0a0fd
Raw diff: https://github.com/php/php-src/commit/6f91fcc866648eb40a4fa2846754d0adcff0a0fd.diff
Merge branch 'PHP-8.4' into PHP-8.5
* PHP-8.4:
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 9960f664fb3e..5f1c1b43877d 100644
--- a/NEWS
+++ b/NEWS
@@ -48,6 +48,10 @@ PHP NEWS
. Fixed imagecreatefromstring() continuing to decode after throwing for a
string longer than INT_MAX. (lacatoire)
+- Intl:
+ . 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 0ab3f6e4eceb..13347722db98 100644
--- a/ext/intl/locale/locale_methods.cpp
+++ b/ext/intl/locale/locale_methods.cpp
@@ -1560,6 +1560,9 @@ U_CFUNC PHP_FUNCTION(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)