Skip to content

Commit b7cc1c1

Browse files
committed
Merge branch 'PHP-8.5'
* PHP-8.5: ext/intl: Sync IntlTimeZone object errors for invalid display types
2 parents 5c5c48f + 534d28a commit b7cc1c1

3 files changed

Lines changed: 10 additions & 3 deletions

File tree

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ PHP NEWS
7070
- Intl:
7171
. Fixed malformed ResourceBundle::get() error message when fallback is
7272
disabled. (Weilin Du)
73+
. Fixed IntlTimeZone::getDisplayName() to synchronize object error state
74+
for invalid display types. (Weilin Du)
7375
. Added IntlNumberRangeFormatter class to format an interval of two numbers
7476
with a given skeleton, locale, collapse type and identity fallback.
7577
(BogdanUngureanu)

ext/intl/tests/timezone_getDisplayName_error.phpt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,12 @@ intl
88
$tz = IntlTimeZone::createTimeZone('Europe/Lisbon');
99
var_dump($tz->getDisplayName(false, -1));
1010
echo intl_get_error_message(), PHP_EOL;
11+
var_dump($tz->getErrorCode());
12+
echo $tz->getErrorMessage(), PHP_EOL;
1113

1214
?>
1315
--EXPECT--
1416
bool(false)
1517
IntlTimeZone::getDisplayName(): wrong display type: U_ILLEGAL_ARGUMENT_ERROR
18+
int(1)
19+
IntlTimeZone::getDisplayName(): wrong display type: U_ILLEGAL_ARGUMENT_ERROR

ext/intl/timezone/timezone_methods.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -483,22 +483,23 @@ U_CFUNC PHP_FUNCTION(intltz_get_display_name)
483483
RETURN_THROWS();
484484
}
485485

486+
TIMEZONE_METHOD_FETCH_OBJECT;
487+
486488
bool found = false;
487489
for (int i = 0; !found && i < sizeof(display_types)/sizeof(*display_types); i++) {
488490
if (display_types[i] == display_type)
489491
found = true;
490492
}
491493
if (!found) {
492-
intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, "wrong display type");
494+
intl_errors_set(TIMEZONE_ERROR_P(to), U_ILLEGAL_ARGUMENT_ERROR,
495+
"wrong display type");
493496
RETURN_FALSE;
494497
}
495498

496499
if (!locale_str) {
497500
locale_str = intl_locale_get_default();
498501
}
499502

500-
TIMEZONE_METHOD_FETCH_OBJECT;
501-
502503
UnicodeString result;
503504
to->utimezone->getDisplayName((UBool)daylight, (TimeZone::EDisplayType)display_type,
504505
Locale::createFromName(locale_str), result);

0 commit comments

Comments
 (0)