Edit report at https://bugs.php.net/bug.php?id=67757&edit=1
ID: 67757
Updated by: [email protected]
Reported by: php at tutteli dot ch
Summary: multiple default cases
-Status: Open
+Status: Wont fix
Type: Bug
Package: PHP Language Specification
PHP Version: 5.5.15
Block user comment: N
Private report: N
New Comment:
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php
I close with won't fix, as we now have an RFC for this case, and a PR as well
Previous Comments:
------------------------------------------------------------------------
[2014-08-13 13:51:50] [email protected]
nevermind me, I'm just an idiot. /o\
------------------------------------------------------------------------
[2014-08-13 11:32:38] [email protected]
I would argue, that the correct output should be 1.
If you replace default with case 1, that is what the output will be, as both of the cases would match in the order of definition, but after the first case we would break out so the second case would never got a chance to be executed.
What's even more interesting is that even the default blocks work this way if there is a normal case block which matches the value in the switch.
here is an example for the original snippet from the bugreport:
http://3v4l.org/9RtL8
here is one for the same but using matching case vs default:
http://3v4l.org/Ioqsq
and here is an example where the defaults behave differently if there is a previous matching case:
http://3v4l.org/r3poR
so I think that the hhvm behavior is correct and the current php behavior is wrong, but this isn't a design problem of the support of multiple defaults but an implementation problem, where we don't properly iterate over the cases from top to bottom.
------------------------------------------------------------------------
[2014-08-06 04:43:44] [email protected]
https://wiki.php.net/rfc/switch.default.multiple
------------------------------------------------------------------------
[2014-08-05 23:32:15] [email protected]
+1 on the spec being the optimal behavior. Don't allow this. PHP5 and HHVM actually differ on behavior here, scarily enough. PHP5 executes the code in the last default. HHVM executes the code in the first default.
------------------------------------------------------------------------
[2014-08-05 23:21:00] [email protected]
FWIW, I'm also in favour of fixing implementations here.
------------------------------------------------------------------------
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=67757
--
Edit this bug report at https://bugs.php.net/bug.php?id=67757&edit=1
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.