-
Notifications
You must be signed in to change notification settings - Fork 7.9k
[RFC] Implement match blocks #11933
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?
[RFC] Implement match blocks #11933
Conversation
b45c117
to
5cbea46
Compare
02e1448
to
3ccbc43
Compare
}); | ||
?> | ||
--EXPECTF-- | ||
Fatal error: 'goto' into loop or switch statement is disallowed in %s on line %d |
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.
The error message should mention “match”.
5444ac5
to
04a31ab
Compare
04a31ab
to
24218f8
Compare
--FILE-- | ||
<?php | ||
$x = null; | ||
$y = $x ?? { |
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.
Is
$x = {
echo "test\n";
null
};
also possible?
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.
No, not in this PR. Please read the RFC, the rationale is explained there. https://wiki.php.net/rfc/match_blocks#why_not_language-level_blocks
https://wiki.php.net/rfc/match_blocks
throw
statements non-terminators in match blocks. Alternatively, [WIP] Auto-extend live-ranges #11880.;
is subtle. We could do<= $value
or some other symbol. The downside is that people may expect this to work anywhere in the block, which is currently not the case. The result must appear at the end of the block. Edit: I've settled on<-
and=>
for now. I picked<-
over<=
because ligatures often render<=
as ≤.This is a much simpler alternative to master...iluuu1994:php-src:match-blocks-var-tracking, which allowed
return
,break
,continue
, andgoto
out of match expression blocks. This PR disallows escaping match blocks whose result value is used. This avoids tracking VARs that may have to be freed if an expression is escaped midway.