Bug #67757 [Com]: multiple default cases

From: Date: Wed, 13 Aug 2014 11:32:39 +0000
Subject: Bug #67757 [Com]: multiple default cases
References: 1  Groups: php.standards 
Request: Send a blank email to standards-+get-379@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=67757&edit=1 ID: 67757 Comment by: tyrael@php.net Reported by: php at tutteli dot ch Summary: multiple default cases Status: Open Type: Bug Package: PHP Language Specification PHP Version: 5.5.15 Block user comment: N Private report: N New Comment: 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. Previous Comments: ------------------------------------------------------------------------ [2014-08-06 04:43:44] pollita@php.net https://wiki.php.net/rfc/switch.default.multiple ------------------------------------------------------------------------ [2014-08-05 23:32:15] joelm@php.net +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] ajf@php.net FWIW, I'm also in favour of fixing implementations here. ------------------------------------------------------------------------ [2014-08-05 23:18:38] pollita@php.net I'd argue that we can look at this either way. It's kind of silly to allow the definition of two defaults in a switch statement, so the question is: Do we define silliness as normal and update the spec, or do we fix a weirdness in the implementation by updating the engine. I for one, vote for the latter. ------------------------------------------------------------------------ [2014-08-05 19:19:15] aharvey@php.net This is probably an issue with the spec, then: AIUI, the spec should be documenting what 5.6 does at present. ------------------------------------------------------------------------ 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

« previous php.standards (#379) next »