Levi Morrison


PHP RFC: Make defining multiple default cases in a switch a syntax error


Bug 67757 notes that the recently introduced PHP language specification differs from PHP's behavior when a switch statement defines multiple default cases. The spec claims the following is a syntax error, while PHP will execute it with the last default block being taken:

switch ($expr) {


This issue can be fixed by altering the spec to match PHP's behavior, or fixing PHP to treat multiple defaults as an error. This RFC opts for the latter; it also provides a deprecation route.

PHP 5.7: Raise E_DEPRECATED each time a default blocks after the first is encountered; continue to execute only the last default block.
PHP 7.0: Raise E_COMPILE_ERROR when multiple default blocks are found.

Backward Incompatible Changes

There may be code out there (maybe generated code?) which relies on being able to define multiple default blocks and having only the last block executed. This RFC takes the position that multiple default blocks was an implementation detail that should not have been relied upon.


Proposed PHP Version(s)

This RFC targets both PHP 5.7 and 7.0.


Version Changed Date
7.0 because of AST merge ( 22:16 UTC
7 Vote opened ( 16:50 UTC
6 Voting cancelled ( 15:35 UTC
5.7 20:42 UTC
5 Levi Morrison claims ownership of RFC ( 17:13 UTC) Changes RFC to target PHP 7 for removal, with deprecations going into PHP 5.7.
4 Changes RFC to target PHP 7 for removal, with deprecations going into PHP 5.7.
2 Voting is open ( 21:19 UTC) and will close in ten days.


An option needs 2/3 votes to win

switch.default.multiple (100% approved)
User Vote
aharvey Yes
ajf Yes
ashnazg Yes
auroraeosrose Yes
ben Yes
brianlmoon Yes
bwoebi Yes
datibbaw Yes
davey Yes
derick Yes
dm Yes
dmitry Yes
fa Yes
fredemmott Yes
frozenfire Yes
jedibc Yes
krakjoe Yes
levim Yes
malukenho Yes
mbeccati Yes
mike Yes
nikic Yes
philstu Yes
ramsey Yes
rdlowrey Yes
salathe Yes
sebastian Yes
stas Yes