rfc:switch.default.multiple

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

Version: 1.0

Date: 2014-08-05

Author: Levi Morrison levim@php.net

Status: Accepted

First Published at: http://wiki.php.net/rfc/switch.default.multiple

Introduction

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) { default: neverExecuted(); break; default: executed(); }

Proposal

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.

Implementation

Proposed PHP Version(s)

This RFC targets both PHP 5.7 and 7.0.

Vote

This RFC modifies the PHP language and requires 2/3 vote in the affirmative to pass. Voting will remain open through Monday, September 15th. Should we deprecate multiple default clauses in switch statements in PHP 5.7 and remove them in PHP 7, as outlined and implemented in this RFC ? switch.default.multiple Real name Yes No aharvey (aharvey) ajf (ajf) ashnazg (ashnazg) auroraeosrose (auroraeosrose) ben (ben) brianlmoon (brianlmoon) bwoebi (bwoebi) datibbaw (datibbaw) davey (davey) derick (derick) dm (dm) dmitry (dmitry) fa (fa) fredemmott (fredemmott) frozenfire (frozenfire) jedibc (jedibc) krakjoe (krakjoe) levim (levim) malukenho (malukenho) mbeccati (mbeccati) mike (mike) nikic (nikic) philstu (philstu) ramsey (ramsey) rdlowrey (rdlowrey) salathe (salathe) sebastian (sebastian) stas (stas) Final result: 28 0 This poll has been closed. Voting was unambiguously in favor of this RFC .

Changelog