Skip to content

Commit 2d15b0b

Browse files
committed
ext/intl: Sync IntlTimeZone object errors for invalid display types
1 parent edde169 commit 2d15b0b

3 files changed

Lines changed: 11 additions & 3 deletions

File tree

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ PHP NEWS
2020
. Fix incorrect argument positions for uninitialized calendar arguments in
2121
IntlCalendar::equals(), ::before(), ::after(), and ::isEquivalentTo().
2222
(Weilin Du)
23+
. Fixed IntlTimeZone::getDisplayName() to synchronize object error state
24+
for invalid display types. (Weilin Du)
2325
. Fixed Spoofchecker restriction-level APIs to only be exposed with ICU 53
2426
and later. (Graham Campbell)
2527

ext/intl/tests/timezone_getDisplayName_error.phpt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,18 @@ ini_set("intl.error_level", E_WARNING);
88

99
$tz = IntlTimeZone::createTimeZone('Europe/Lisbon');
1010
var_dump($tz->getDisplayName(false, -1));
11+
echo intl_get_error_message(), PHP_EOL;
12+
var_dump($tz->getErrorCode());
13+
echo $tz->getErrorMessage(), PHP_EOL;
1114

1215
var_dump(intltz_get_display_name(null, IntlTimeZone::DISPLAY_SHORT, false, 'pt_PT'));
1316
?>
1417
--EXPECTF--
1518
Warning: IntlTimeZone::getDisplayName(): wrong display type in %s on line %d
1619
bool(false)
20+
IntlTimeZone::getDisplayName(): wrong display type: U_ILLEGAL_ARGUMENT_ERROR
21+
int(1)
22+
wrong display type: U_ILLEGAL_ARGUMENT_ERROR
1723

1824
Fatal error: Uncaught TypeError: intltz_get_display_name(): Argument #1 ($timezone) must be of type IntlTimeZone, null given in %s:%d
1925
Stack trace:

ext/intl/timezone/timezone_methods.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -513,13 +513,15 @@ U_CFUNC PHP_FUNCTION(intltz_get_display_name)
513513
RETURN_THROWS();
514514
}
515515

516+
TIMEZONE_METHOD_FETCH_OBJECT;
517+
516518
bool found = false;
517519
for (int i = 0; !found && i < sizeof(display_types)/sizeof(*display_types); i++) {
518520
if (display_types[i] == display_type)
519521
found = true;
520522
}
521523
if (!found) {
522-
intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR,
524+
intl_errors_set(TIMEZONE_ERROR_P(to), U_ILLEGAL_ARGUMENT_ERROR,
523525
"wrong display type", 0);
524526
RETURN_FALSE;
525527
}
@@ -528,8 +530,6 @@ U_CFUNC PHP_FUNCTION(intltz_get_display_name)
528530
locale_str = intl_locale_get_default();
529531
}
530532

531-
TIMEZONE_METHOD_FETCH_OBJECT;
532-
533533
UnicodeString result;
534534
to->utimezone->getDisplayName((UBool)daylight, (TimeZone::EDisplayType)display_type,
535535
Locale::createFromName(locale_str), result);

0 commit comments

Comments
 (0)