-
Notifications
You must be signed in to change notification settings - Fork 7.8k
fix: disallow using multiple throw expressions #18512
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
base: master
Are you sure you want to change the base?
Conversation
This doesn't stop me from writing variations of this: throw ((throw new Exception) ?? 1); There are many such variations and you can't cover all of them with a simple AST check. |
@nielsdos any thought how to prevent so? |
But why do we need to prevent it at all? Compilers accept dumb programs, we can't possibly reject all of them (without also rejecting valid ones). |
I suppose you'd have to recursively check the AST subtree. But I agree with Ilija that trying to prevent this at compile time is likely not worth the hassle. |
In any case it would also be a breaking change (legal PHP programs become illegal) and thus would require an RFC. |
Should I close this then? |
@xepozz You are free to create an RFC if you like. Such a check would be possible to implement by traversing the AST, or recording the fact that we're inside a throw expression and checking this flag in If you're not interested in creating an RFC, then yes, please close the issue. |
I've thought about it, but it will degrade performance, won't it? Also checking a flag in
|
Performance in the compiler is not particularly crucial, plus you can avoid the slowdown almost completely by storing a boolean flag in
This is not a concern. The call is not followed at compile-time. |
Preventing
throw throw throw ...
hellhttps://3v4l.org/nJ65d