rfc:switch.default.multiple

This is an old revision of the document!


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

Introduction

Bug 67757 notes that the recently introduced PHP Language spec differs from PHP's behavior in the case of a switch statement defining multiple default cases. The spec claims the following is a syntax error, while PHP will execute it just fine (resulting in the latter default block being taken).

switch ($expr) {
  default:
    neverExecuted();
    break;
  default:
    executed();
}

Proposal

We have the choice of either fixing the spec to match PHP's behavior, or fixing PHP to treat multiple defaults as a bad idea.

I propose we make defining multiple default cases in a switch statement a syntax error (E_COMPILE_ERROR).

Backward Incompatible Changes

Theoretically 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, but this seems pretty broken-by-design.

Proposed PHP Version(s)

PHP 5.next

Vote

While this impacts syntax, it doesn't really modify what is valid PHP, it just solidifies what best practices should consider correct, therefor I'm proposing this as a standard 50%+1 vote.

Should defining more than one default block in a switch statement produce a synatx error?
Real name Yes No
aharvey (aharvey)  
ajf (ajf)  
andi (andi)  
bwoebi (bwoebi)  
datibbaw (datibbaw)  
davey (davey)  
derick (derick)  
dm (dm)  
dragoonis (dragoonis)  
fa (fa)  
fredemmott (fredemmott)  
gwynne (gwynne)  
hywan (hywan)  
jedibc (jedibc)  
jwage (jwage)  
kalle (kalle)  
klaussilveira (klaussilveira)  
krakjoe (krakjoe)  
lstrojny (lstrojny)  
mfonda (mfonda)  
mrook (mrook)  
nikic (nikic)  
pollita (pollita)  
preinheimer (preinheimer)  
rasmus (rasmus)  
salathe (salathe)  
sean (sean)  
sebastian (sebastian)  
tony2001 (tony2001)  
tyrael (tyrael)  
weierophinney (weierophinney)  
whatthejeff (whatthejeff)  
zeev (zeev)  
Final result: 31 2
This poll has been closed.

Vote opened 2014-08-12 16:50 UTC
Voting cancelled 2014-08-13 15:35 UTC

Implementation

rfc/switch.default.multiple.1407944149.txt.gz · Last modified: 2017/09/22 13:28 (external edit)