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
[RFC] Convert exit (and die) from language constructs to functions #13483
base: master
Are you sure you want to change the base?
Conversation
Zend/zend_execute.c
Outdated
if (UNEXPECTED( | ||
zend_string_equals_literal_ci(Z_STR_P(key), "exit") | ||
|| zend_string_equals_literal_ci(Z_STR_P(key), "die") | ||
)) { | ||
zend_throw_unwind_exit(); | ||
return FAILURE; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we achieve similar results with by de-sugaring exit;
to a function call at the AST level? (e.g. zend_compile_const()
can replace the AST with a function call AST and delegate to zend_compile_call()
). This would remove the need for special cases at runtime, and also unify the behavior of exit;
and exit();
(wrt to disable_functions).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree. Special-casing exit/die constant access doesn't sound like a cleaner solution than what we have now. Keeping them in the lexer/parser also keeps BC for AST-based tools.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, and it has side effects like defined(), constant() calls etc.
We may opt to special-case only statement-level "exit" and "die" constant fetches directly (i.e. handle in zend_compile_stmt, in the branch for constants).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, that's actually a smarter way of doing it!
I'll see if I can implement this, as I still struggle with the compiler part.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We may opt to special-case only statement-level "exit" and "die" constant fetches directly (i.e. handle in zend_compile_stmt, in the branch for constants).
I would prefer keeping parser support, as otherwise PHPStan and the likes need to adjust. I don't think there's a reason to break those. Edit: I guess lexer would be sufficient, as almost all of these tools use PHPParser, which defines its own AST. Still, I'd prefer letting the parser handle this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was about to suggest something similar, because exit;
not actually calling the function but just throwing that unwind exception probably leads to observable behavioral differences in debuggers dependent on whether the user wrote exit;
or exit();
, no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we should constrain ourselves with respect to phpstan etc.; there are worse BC breaks to be had.
I think the lexer, parser and opcodes are aside from any compatibilty guarantees.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ondrejmirtes has told me that this shouldn't be an issue if PHPParser still works, I'm asking @dseguy if this would affect Exakat or not.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@exakat will need an adaptation, at the parser level. That is not an issue.
0549f75
to
89aaa8f
Compare
Where is the RFC? Removing ability to use Please consider the possibility of adding die/exit functions without removing opcodes. |
@dstogov See zend_compile.c, the constants are turned into function calls. That said, I'm also a bit sceptical about the proposed benefits. I think an RFC, or at least a list on the mailing list explaining the rationale would be reasonable. |
The PR name contains |
Nice hack :), but it needs to be verified (constants may be used in places where calls are not allowed). |
The RFC is now live: https://wiki.php.net/rfc/exit-as-function and I have sent an email to internals. I'm still somewhat ill so I didn't manage to post it yesterday. |
The main motivation here is to have the same type juggling semantics as every other function in PHP.
Also, we don't need to have an opcode any more for it.
RFC: https://wiki.php.net/rfc/exit-as-function