|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #67757 multiple default cases
Submitted: 2014-08-04 12:31 UTC Modified: 2015-01-09 15:15 UTC
From: php at tutteli dot ch Assigned:
Status: Wont fix Package: PHP Language Specification
PHP Version: 5.5.15 OS:
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: php at tutteli dot ch
New email:
PHP Version: OS:


 [2014-08-04 12:31 UTC] php at tutteli dot ch
PHP allows to define multiple default cases in a switch. According to the spec this should not be allowed:

Test script:
switch($a) {
    $b += 1;
    $b += 2;
echo $b; //output would be 2

Expected result:
parser syntax error


Add a Patch

Pull Requests

Pull requests:

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2014-08-05 19:19 UTC]
-Package: *General Issues +Package: PHP Language Specification
 [2014-08-05 19:19 UTC]
This is probably an issue with the spec, then: AIUI, the spec should be documenting what 5.6 does at present.
 [2014-08-05 23:18 UTC]
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 23:21 UTC]
FWIW, I'm also in favour of fixing implementations here.
 [2014-08-05 23:32 UTC]
+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-13 11:32 UTC]
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:
here is one for the same but using matching case vs default:
and here is an example where the defaults behave differently if there is a previous matching case:

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-13 13:51 UTC]
nevermind me, I'm just an idiot. /o\
 [2015-01-09 15:15 UTC]
-Status: Open +Status: Wont fix
 [2015-01-09 15:15 UTC]
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at and the instructions on how to report
a bug at

I close with won't fix, as we now have an RFC for this case, and a PR as well
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Tue Dec 05 02:01:26 2023 UTC