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..8cecb40ecfea 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) +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);