Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IntlDateFormatter fatal error in PHP 8.1.26 #12912

Closed
randeraad opened this issue Dec 9, 2023 · 2 comments
Closed

IntlDateFormatter fatal error in PHP 8.1.26 #12912

randeraad opened this issue Dec 9, 2023 · 2 comments

Comments

@randeraad
Copy link

Description

Related to: #12282

In PHP 8.1.24 it was possible to use IntlDateFormatter with an invalid locale: IntlDateFormatter::create('xx');
In PHP 8.1.25 the same code would fail and throw an exception.
In PHP 8.1.26 the exception is no longer thrown, but the object is unconstructed and using it generates a fatal error.

$obj = IntlDateFormatter::create('xx');
$obj->getCalendar(); // Fatal error: Uncaught Error: Found unconstructed IntlDateFormatter

How can we check if the IntlDateFormatter object is constructed without generating a fatal error?

PHP Version

PHP 8.1.26

Operating System

No response

@devnexen
Copy link
Member

devnexen commented Dec 9, 2023

Would it work if you try/catch as ?

try {
    $obj = IntlDateFormatter::create('xx');
    $obj->getCalendar();
} catch (\Error $e) {
    ...
}

@randeraad
Copy link
Author

Thank you, catching the error works. I tried catching the exception and that failed.

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

No branches or pull requests

2 participants