This is an old revision of the document!
PHP RFC: Make defining multiple default cases in a switch a syntax error
- Version: 1.0
- Date: 2014-08-05
- Author: Sara Golemon, pollita@php.net
- Status: In Voting
- First Published at: http://wiki.php.net/rfc/switch.default.multiple
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.
Vote opened 2014-08-12 16:50 UTC
Vote will close 2014-08-19 17:00 UTC