From 2d15b0b7bdbe7a08fbd2ff554ea8d117afa03aed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CLamentXU123=E2=80=9D?= <108666168+LamentXU123@users.noreply.github.com> Date: Thu, 11 Jun 2026 01:19:00 +0800 Subject: [PATCH 1/2] ext/intl: Sync IntlTimeZone object errors for invalid display types --- NEWS | 2 ++ ext/intl/tests/timezone_getDisplayName_error.phpt | 6 ++++++ ext/intl/timezone/timezone_methods.cpp | 6 +++--- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/NEWS b/NEWS index 2698420c7a5a..ff30d531636d 100644 --- a/NEWS +++ b/NEWS @@ -20,6 +20,8 @@ PHP NEWS . Fix incorrect argument positions for uninitialized calendar arguments in IntlCalendar::equals(), ::before(), ::after(), and ::isEquivalentTo(). (Weilin Du) + . Fixed IntlTimeZone::getDisplayName() to synchronize object error state + for invalid display types. (Weilin Du) . Fixed Spoofchecker restriction-level APIs to only be exposed with ICU 53 and later. (Graham Campbell) diff --git a/ext/intl/tests/timezone_getDisplayName_error.phpt b/ext/intl/tests/timezone_getDisplayName_error.phpt index ce3ab2f7e766..6b6029bdd6d2 100644 --- a/ext/intl/tests/timezone_getDisplayName_error.phpt +++ b/ext/intl/tests/timezone_getDisplayName_error.phpt @@ -8,12 +8,18 @@ ini_set("intl.error_level", E_WARNING); $tz = IntlTimeZone::createTimeZone('Europe/Lisbon'); var_dump($tz->getDisplayName(false, -1)); +echo intl_get_error_message(), PHP_EOL; +var_dump($tz->getErrorCode()); +echo $tz->getErrorMessage(), PHP_EOL; var_dump(intltz_get_display_name(null, IntlTimeZone::DISPLAY_SHORT, false, 'pt_PT')); ?> --EXPECTF-- Warning: IntlTimeZone::getDisplayName(): wrong display type in %s on line %d bool(false) +IntlTimeZone::getDisplayName(): wrong display type: U_ILLEGAL_ARGUMENT_ERROR +int(1) +wrong display type: U_ILLEGAL_ARGUMENT_ERROR Fatal error: Uncaught TypeError: intltz_get_display_name(): Argument #1 ($timezone) must be of type IntlTimeZone, null given in %s:%d Stack trace: diff --git a/ext/intl/timezone/timezone_methods.cpp b/ext/intl/timezone/timezone_methods.cpp index ec7ad9942fd8..e3aa958508c1 100644 --- a/ext/intl/timezone/timezone_methods.cpp +++ b/ext/intl/timezone/timezone_methods.cpp @@ -513,13 +513,15 @@ U_CFUNC PHP_FUNCTION(intltz_get_display_name) RETURN_THROWS(); } + TIMEZONE_METHOD_FETCH_OBJECT; + bool found = false; for (int i = 0; !found && i < sizeof(display_types)/sizeof(*display_types); i++) { if (display_types[i] == display_type) found = true; } if (!found) { - intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, + intl_errors_set(TIMEZONE_ERROR_P(to), U_ILLEGAL_ARGUMENT_ERROR, "wrong display type", 0); RETURN_FALSE; } @@ -528,8 +530,6 @@ U_CFUNC PHP_FUNCTION(intltz_get_display_name) locale_str = intl_locale_get_default(); } - TIMEZONE_METHOD_FETCH_OBJECT; - UnicodeString result; to->utimezone->getDisplayName((UBool)daylight, (TimeZone::EDisplayType)display_type, Locale::createFromName(locale_str), result); From 4b5040049150e480e36e33f66bd38ccda6bb674a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CLamentXU123=E2=80=9D?= <108666168+LamentXU123@users.noreply.github.com> Date: Thu, 11 Jun 2026 13:05:59 +0800 Subject: [PATCH 2/2] fix CI --- ext/intl/tests/timezone_getDisplayName_error.phpt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/intl/tests/timezone_getDisplayName_error.phpt b/ext/intl/tests/timezone_getDisplayName_error.phpt index 6b6029bdd6d2..8cecb40ecfea 100644 --- a/ext/intl/tests/timezone_getDisplayName_error.phpt +++ b/ext/intl/tests/timezone_getDisplayName_error.phpt @@ -17,7 +17,7 @@ var_dump(intltz_get_display_name(null, IntlTimeZone::DISPLAY_SHORT, false, 'pt_P --EXPECTF-- Warning: IntlTimeZone::getDisplayName(): wrong display type in %s on line %d bool(false) -IntlTimeZone::getDisplayName(): wrong display type: U_ILLEGAL_ARGUMENT_ERROR +wrong display type: U_ILLEGAL_ARGUMENT_ERROR int(1) wrong display type: U_ILLEGAL_ARGUMENT_ERROR