Skip to content

ext/intl: Sync IntlTimeZone object errors for invalid display types#22270

Closed
LamentXU123 wants to merge 2 commits into
php:PHP-8.4from
LamentXU123:fix-timezone-error-code
Closed

ext/intl: Sync IntlTimeZone object errors for invalid display types#22270
LamentXU123 wants to merge 2 commits into
php:PHP-8.4from
LamentXU123:fix-timezone-error-code

Conversation

@LamentXU123

@LamentXU123 LamentXU123 commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

Now, IntlTimeZone::getDisplayName() handled invalid display_type values before fetching the object, so it only updated the global intl error state.

That is,

<?php
$tz = IntlTimeZone::createTimeZone('Europe/Lisbon');
var_dump($tz->getDisplayName(false, -1));
var_dump(intl_get_error_message());
var_dump($tz->getErrorCode());
var_dump($tz->getErrorMessage());

returns

bool(false)
string(76) "IntlTimeZone::getDisplayName(): wrong display type: U_ILLEGAL_ARGUMENT_ERROR"
int(0)
string(12) "U_ZERO_ERROR"

but I expect

bool(false)
string(76) "IntlTimeZone::getDisplayName(): wrong display type: U_ILLEGAL_ARGUMENT_ERROR"
int(1)
string(44) "wrong display type: U_ILLEGAL_ARGUMENT_ERROR"

The solution is to move TIMEZONE_METHOD_FETCH_OBJECT after the intl_errors_set func being called. So the object error state is correctly changed.

@LamentXU123 LamentXU123 marked this pull request as ready for review June 10, 2026 17:22
@LamentXU123 LamentXU123 requested a review from devnexen as a code owner June 10, 2026 17:22
@devnexen

Copy link
Copy Markdown
Member

good, the fix looks correct. it is consistent with intltz_has_same_rules.

One thing to note in the description: fetching before the display-type check means an unconstructed IntlTimeZone now throws Found unconstructed IntlTimeZone instead
of returning false. Only reachable via newInstanceWithoutConstructor(), and it's arguably more correct, so fine for 8.4, just worth stating it's intentional.

@LamentXU123

Copy link
Copy Markdown
Contributor Author

Ah got it. Thanks for reviewing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants