# RFC: switch.default.multiple

- Status: Implemented (PHP 7.0)
- Authors: Levi Morrison levim@php.net
- Date: 2014-08-05
- Version: 1.0
- Original: https://wiki.php.net/rfc/switch.default.multiple
- Page: https://externals.io/rfc/switch.default.multiple
- More for agents: search with https://externals.io/search.md?q={query} · RFCs at https://externals.io/rfc.md · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

## Votes

### switch.default.multiple (closed)

Yes: 28 · No: 0

Voters: aharvey (Yes), ajf (Yes), ashnazg (Yes), auroraeosrose (Yes), ben (Yes), brianlmoon (Yes), bwoebi (Yes), datibbaw (Yes), davey (Yes), derick (Yes), dm (Yes), dmitry (Yes), fa (Yes), fredemmott (Yes), frozenfire (Yes), jedibc (Yes), krakjoe (Yes), levim (Yes), malukenho (Yes), mbeccati (Yes), mike (Yes), nikic (Yes), philstu (Yes), ramsey (Yes), rdlowrey (Yes), salathe (Yes), sebastian (Yes), stas (Yes)

## Discussions on the mailing list

- [\[RFC\] Disallow multiple default blocks in a single switch statement](https://externals.io/message/76368.md) — started on 2014-08-06, 48 messages
- [\[VOTE\] Mutliple defaults in switch statements](https://externals.io/message/76449.md) — started on 2014-08-12, 10 messages
- [\[VOTE\] Removing Multiple Default Clauses in Switch Statements](https://externals.io/message/77080.md) — started on 2014-09-05, 7 messages

---

## Introduction

[Bug 67757](https://bugs.php.net/bug.php?id=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

- PHP 5.7: <https://github.com/php/php-src/pull/807>
- PHP 7.0: <https://github.com/php/php-src/pull/808> (commit [6967f78cc95ef6166f82dcb7e4395f594ce5ad0b](http://git.php.net/?p=php-src.git;a=commit;h=6967f78cc95ef6166f82dcb7e4395f594ce5ad0b))

Already landed in HHVM:

- <https://github.com/facebook/hhvm/commit/e77e2f74f9fd0619d5ae0555695d327af7dadffd>

## 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?

**Vote: switch.default.multiple** — Yes: 28 · No: 0 (closed)

Voting was unambiguously in favor of this RFC.

## 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.
- Added implementation for PHP 5.7 (2014-09-05 20:42 UTC)
- Voting is open (2014-09-05 21:19 UTC) and will close in ten days.
- Updated implementation for PHP 7.0 because of AST merge (2014-09-05 22:16 UTC)
