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  
ajf  
andi  
bwoebi  
datibbaw  
davey  
derick  
dm  
dragoonis  
fa  
fredemmott  
gwynne  
hywan  
jedibc  
jwage  
kalle  
klaussilveira  
krakjoe  
lstrojny  
mfonda  
mrook  
nikic  
pollita  
preinheimer  
rasmus  
salathe  
sean  
sebastian  
tony2001  
tyrael  
weierophinney  
whatthejeff  
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: (external edit)