Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
6 changes: 6 additions & 0 deletions ext/intl/tests/timezone_getDisplayName_error.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 3 additions & 3 deletions ext/intl/timezone/timezone_methods.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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);
Expand Down
Loading