From fdee518d19d0b6f92c9d243cb0c1b67d66c4cbec 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] ext/intl: Fix ResourceBundle fallback-disabled error message --- NEWS | 2 ++ UPGRADING | 3 +++ .../resourcebundle/resourcebundle_class.cpp | 6 +++--- .../resourcebundle_get_without_fallback.phpt | 19 +++++++++++++++++++ 4 files changed, 27 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..d167a7c5c011 --- /dev/null +++ b/ext/intl/tests/resourcebundle_get_without_fallback.phpt @@ -0,0 +1,19 @@ +--TEST-- +ResourceBundle::get() rejects fallback results when fallback is disabled with correct error message +--EXTENSIONS-- +intl +--FILE-- +get('testint', false)); + +$bundle = resourcebundle_create('es', BUNDLE); +echo debug(resourcebundle_get($bundle, 'testint', false)); +?> +--EXPECTF-- +NULL + %i: Cannot load element 'testint' without fallback to %s: U_USING_%s_WARNING +NULL + %i: Cannot load element 'testint' without fallback to %s: U_USING_%s_WARNING