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 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 just fine (resulting in the latter 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:

PHP 5.7: Raise E_DEPRECATED when multiple default blocks are found; continue to execute only the last default block. PHP 7.0: Raise E_COMPILE_ERRORwhen 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 propose that multiple default blocks will generate an E_COMPILE_ERROR and fail in PHP 7, and in PHP 5.7 it will generate an E_DEPRECATED warning and continue.

Vote

Implementation

Changelog

  • Vote opened (2014-08-12 16:50 UTC)
  • Voting cancelled (2014-08-13 15:35 UTC)
  • Levi Morrison claims ownership of RFC (2014-08-14 17:13 UTC)
    • Changes RFC to target PHP 7 for removal, with deprecations going into PHP 5.7.
rfc/switch.default.multiple.1408047044.txt.gz · Last modified: 2017/09/22 13:28 (external edit)