Skip to content

Constant causes an uncatchable fatal error when given non-existent class #9930

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

Closed
ciaranmcnulty opened this issue Nov 11, 2022 · 2 comments
Closed

Comments

@ciaranmcnulty
Copy link

ciaranmcnulty commented Nov 11, 2022

Description

The following code:

var_dump(defined('Foo::FOO'));

try {
  $class = constant('Foo::FOO');
} catch (\Throwable $e) {
  echo "I caught it!";
}

Resulted in this output:

bool(false)

Fatal error: Class "Foo" not found in /in/7tWT2 on line 6

Process exited with code 255.

But I expected this output instead:

bool(false)
I caught it!

i.e. the error should be caught as a throwable Error, as is the behaviour of constant since 8.0.0

PHP Version

PHP 8.1.12

Operating System

No response

@cmb69
Copy link
Member

cmb69 commented Nov 11, 2022

Fascinating! That bug existed for years, and now it has been reported twice within a few days. Anyhow, already solved now (see #9905).

@cmb69 cmb69 closed this as not planned Won't fix, can't repro, duplicate, stale Nov 11, 2022
@ciaranmcnulty
Copy link
Author

@cmb69 hah great, I triggered it just today by doing something with an enum :)

Possibly https://wiki.php.net/rfc/dynamic_class_constant_fetch has sparked interest in this current way of doing it?

ciaranmcnulty added a commit to ciaranmcnulty/cucumber-gherkin that referenced this issue Nov 11, 2022
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