From 3841a82a3d5c40496d0ccac52c89e6867f37e3c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CLamentXU123=E2=80=9D?= <108666168+LamentXU123@users.noreply.github.com> Date: Sat, 6 Jun 2026 01:03:18 +0800 Subject: [PATCH 1/2] ext/intl: Fix ResourceBundle fallback-disabled error message --- NEWS | 2 ++ UPGRADING | 3 +++ .../resourcebundle/resourcebundle_class.cpp | 6 ++--- .../resourcebundle_get_without_fallback.phpt | 26 +++++++++++++++++++ 4 files changed, 34 insertions(+), 3 deletions(-) create mode 100644 ext/intl/tests/resourcebundle_get_without_fallback.phpt diff --git a/NEWS b/NEWS index 496b61ef81b1..62785b41caf4 100644 --- a/NEWS +++ b/NEWS @@ -61,6 +61,8 @@ PHP NEWS . Upgrade xxHash to 0.8.2. (timwolla) - Intl: + . Fixed malformed ResourceBundle::get() error message when fallback is + disabled. (Weilin Du) . Added IntlNumberRangeFormatter class to format an interval of two numbers with a given skeleton, locale, collapse type and identity fallback. (BogdanUngureanu) diff --git a/UPGRADING b/UPGRADING index 679fc0b552d9..2ec6ce92aa52 100644 --- a/UPGRADING +++ b/UPGRADING @@ -47,6 +47,9 @@ PHP 8.6 UPGRADE NOTES . UConverter::transcode() now rejects from_subst and to_subst option values longer than 127 bytes instead of silently truncating the length before passing it to ICU. + . ResourceBundle::get() and resourcebundle_get() now report fallback-disabled + resource lookups with "without fallback to " instead of the + malformed "without fallback from to ". - PCNTL: . pcntl_alarm() now raises a ValueError if the seconds argument is diff --git a/ext/intl/resourcebundle/resourcebundle_class.cpp b/ext/intl/resourcebundle/resourcebundle_class.cpp index 43823137e605..2a89b14cc6e5 100644 --- a/ext/intl/resourcebundle/resourcebundle_class.cpp +++ b/ext/intl/resourcebundle/resourcebundle_class.cpp @@ -220,12 +220,12 @@ static zval *resource_bundle_array_fetch( } if (!fallback && (INTL_DATA_ERROR_CODE(rb) == U_USING_FALLBACK_WARNING || INTL_DATA_ERROR_CODE(rb) == U_USING_DEFAULT_WARNING)) { - UErrorCode icuerror; + UErrorCode icuerror = U_ZERO_ERROR; const char * locale = ures_getLocaleByType( rb->me, ULOC_ACTUAL_LOCALE, &icuerror ); if (is_numeric) { - spprintf(&pbuf, 0, "Cannot load element %d without fallback from to %s", index, locale); + spprintf(&pbuf, 0, "Cannot load element %d without fallback to %s", index, locale); } else { - spprintf(&pbuf, 0, "Cannot load element '%s' without fallback from to %s", key, locale); + spprintf(&pbuf, 0, "Cannot load element '%s' without fallback to %s", key, locale); } intl_errors_set_custom_msg( INTL_DATA_ERROR_P(rb), pbuf); efree(pbuf); diff --git a/ext/intl/tests/resourcebundle_get_without_fallback.phpt b/ext/intl/tests/resourcebundle_get_without_fallback.phpt new file mode 100644 index 000000000000..14415fa1bf19 --- /dev/null +++ b/ext/intl/tests/resourcebundle_get_without_fallback.phpt @@ -0,0 +1,26 @@ +--TEST-- +ResourceBundle::get() rejects fallback results when fallback is disabled with correct error message +--EXTENSIONS-- +intl +--FILE-- +get('Version', false)); + +$bundle = resourcebundle_create('de_DE', 'ICUDATA'); +echo debug(resourcebundle_get($bundle, 'Version', false)); +?> +--EXPECTF-- +NULL + %i: ResourceBundle::get(): Cannot load element 'Version' without fallback to %s: U_USING_%s_WARNING +NULL + %i: resourcebundle_get(): Cannot load element 'Version' without fallback to %s: U_USING_%s_WARNING From 6bf0367a9585f4448bf37a7c5ded5f00be41e39c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CLamentXU123=E2=80=9D?= <108666168+LamentXU123@users.noreply.github.com> Date: Sun, 7 Jun 2026 15:40:58 +0800 Subject: [PATCH 2/2] fix test --- .../resourcebundle_get_without_fallback.phpt | 48 ++++++++++++++----- 1 file changed, 35 insertions(+), 13 deletions(-) diff --git a/ext/intl/tests/resourcebundle_get_without_fallback.phpt b/ext/intl/tests/resourcebundle_get_without_fallback.phpt index 14415fa1bf19..9f9941227972 100644 --- a/ext/intl/tests/resourcebundle_get_without_fallback.phpt +++ b/ext/intl/tests/resourcebundle_get_without_fallback.phpt @@ -4,23 +4,45 @@ ResourceBundle::get() rejects fallback results when fallback is disabled with co intl --FILE-- get('Version', false)); +// Keep the binary layout intact while making this key fall back to root.res. +$enBundle = file_get_contents(BUNDLE . '/es.res'); +$enBundle = str_replace('teststring', 'teststrinh', $enBundle, $replacementCount); +if ($replacementCount !== 1) { + die("Failed to prepare resource bundle fixture\n"); +} +file_put_contents($fixture . '/en.res', $enBundle); -$bundle = resourcebundle_create('de_DE', 'ICUDATA'); -echo debug(resourcebundle_get($bundle, 'Version', false)); +$bundle = new ResourceBundle('en', $fixture); +echo debug($bundle->get('teststring', false)); + +$bundle = resourcebundle_create('en', $fixture); +echo debug(resourcebundle_get($bundle, 'teststring', false)); ?> --EXPECTF-- NULL - %i: ResourceBundle::get(): Cannot load element 'Version' without fallback to %s: U_USING_%s_WARNING + %i: ResourceBundle::get(): Cannot load element 'teststring' without fallback to %s: U_USING_%s_WARNING NULL - %i: resourcebundle_get(): Cannot load element 'Version' without fallback to %s: U_USING_%s_WARNING + %i: resourcebundle_get(): Cannot load element 'teststring' without fallback to %s: U_USING_%s_WARNING +--CLEAN-- +