-
Notifications
You must be signed in to change notification settings - Fork 7.8k
Using enum as array key in class constant correctly results in error, but line number is inaccurate #8821
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
Comments
I think #8124 should cover this. 3v4l |
Maybe I misunderstand, but it looks like that PR was closed without merging. So I'm not sure how it would have gotten into |
We don't always merge via GitHub, the merged commit is e3ef7bb. |
I checked, doesn't look like the correct line is reported on |
Thanks! |
Description
The following code:
Resulted in this output:
But I expected this output instead:
tl;dr: Yes, I know you can't use an enum as an array key. The problem here is that PHP reported the error as being on the wrong line, making the real problem hard to find.
To elaborate: PHP tells me the error is at
new Bravo()
, but the actual problem is on the line where the const is defined. In the trivial case above, figuring it out is easy, but in actual production code, thenew
might be in another file entirely andclass Bravo
might be hundreds of lines long, concealing where the error really is. Yes, I know static analysis tools would correctly find the problem; this is still an error in PHP's engine.I reproduced this using 3v4l.org, in addition to on my local machine, just to make sure any of my ini settings or extensions weren't affecting things.
PHP Version
PHP 8.1.7
Operating System
No response
The text was updated successfully, but these errors were encountered: