Req #78304 [Opn->Sus]: Switch statement and first case cannot be in separate code blocks
Edit report at https://bugs.php.net/bug.php?id=78304&edit=1
ID: 78304
Updated by: cmb@php.net
Reported by: benjamin dot morel at gmail dot com
Summary: Switch statement and first case cannot be in
separate code blocks
-Status: Open
+Status: Suspended
Type: Feature/Change Request
Package: Scripting Engine problem
Operating System: Fedora
PHP Version: 7.3.7
Block user comment: N
Private report: N
New Comment:
> I think that this FR should be discussed on internals (or
> abandoned).
I'm suspending this ticket. Feel free to pursue the RFC
process[1].
[1] <https://wiki.php.net/rfc/howto>
Previous Comments:
------------------------------------------------------------------------
[2019-07-19 12:54:58] cmb@php.net
As has been explained, this is not a bug, so I'm changing to
feature request.
I think that this FR should be discussed on internals (or
abandoned).
------------------------------------------------------------------------
[2019-07-17 11:07:22] benjamin dot morel at gmail dot com
The idea would be:
- T_SWITCH
- (...):
- T_CLOSE_TAG
- T_INLINE_HTML containing only whitepace
- T_OPEN_TAG
Would drop the last 3 tokens. Isn't that feasible?
------------------------------------------------------------------------
[2019-07-17 10:47:29] requinix@php.net
If the indentation is located between the switch and first case then when should it be outputted?
For all cases? For only the first one? Or should it not be outputted at all?
Avoid the whole problem with
<?php switch ($type): case 'a': ?>
------------------------------------------------------------------------
[2019-07-17 10:33:06] benjamin dot morel at gmail dot com
Thanks for the explanation! I forgot about the collapsing newline (but not spaces) after the closing
tag.
Although this makes sense, it's also very confusing in the present case (pun intended).
First of all this obviously also happens when both lines are indented:
Works:
<?php switch ($type): ?>
<?php case 'a': ?>
...
Fails:
<?php switch ($type): ?>
<?php case 'a': ?>
...
And it does allow whitespace between 'break' and 'case' blocks:
<?php break; ?>
<?php case 'b': ?>
Which is because, as I just discovered, (unreachable) statements are allowed between break and case
in PHP.
All in all, the switch...case seems to be the only place that exhibits this odd behaviour.
Couldn't the parser handle this edge case?
------------------------------------------------------------------------
[2019-07-17 10:11:44] nikic@php.net
As the error message indicates, your problem here is the indentation. Doing something like
<?php switch ($type): ?>
<?php case 'a': ?>
will work fine. But as you indented the case block, you are basically doing the equivalent of:
switch ($type): ;
echo ' ';
case 'a':
which is of course not allowed.
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
https://bugs.php.net/bug.php?id=78304
--
Edit this bug report at https://bugs.php.net/bug.php?id=78304&edit=1
Thread (7 messages)