rfc:switch.default.multiple

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
rfc:switch.default.multiple [2014/08/13 15:35] pollitarfc:switch.default.multiple [2017/09/22 13:28] (current) – external edit 127.0.0.1
Line 2: Line 2:
   * Version: 1.0   * Version: 1.0
   * Date: 2014-08-05   * Date: 2014-08-05
-  * Author: Sara Golemon, pollita@php.net +  * Author: Levi Morrison <levim@php.net> 
-  * Status: Bikeshedding+  * Status: Accepted
   * First Published at: http://wiki.php.net/rfc/switch.default.multiple   * First Published at: http://wiki.php.net/rfc/switch.default.multiple
  
 ===== Introduction ===== ===== Introduction =====
  
-[[https://bugs.php.net/bug.php?id=67757|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).+[[https://bugs.php.net/bug.php?id=67757|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) {   switch ($expr) {
Line 20: Line 20:
 ===== Proposal ===== ===== 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.+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 deprecation route.
  
-I propose we make defining multiple default cases in switch statement a syntax error (E_COMPILE_ERROR).+PHP 5.7: Raise ''E_DEPRECATED'' each time 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 ===== ===== 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.+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 [[http://git.php.net/?p=php-src.git;a=commit;h=6967f78cc95ef6166f82dcb7e4395f594ce5ad0b|6967f78cc95ef6166f82dcb7e4395f594ce5ad0b]]) 
 + 
 +Already landed in HHVM: 
 +  * https://github.com/facebook/hhvm/commit/e77e2f74f9fd0619d5ae0555695d327af7dadffd
  
 ===== Proposed PHP Version(s) ===== ===== Proposed PHP Version(s) =====
  
-PHP 5.next+This RFC targets both PHP 5.7 and 7.0.
  
 ===== Vote ===== ===== 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.+This RFC modifies the PHP language and requires 2/3 vote in the affirmative to pass. Voting will remain open through MondaySeptember 15th.
  
-<doodle title="Should defining more than one default block in a switch statement produce a synatx error?" auth="pollita" voteType="single" closed="true">+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? 
 + 
 +<doodle title="switch.default.multiple" auth="levim" voteType="single" closed="true">
    * Yes    * Yes
    * No    * No
 </doodle> </doodle>
  
-Vote opened 2014-08-12 16:50 UTC \\ +Voting was unambiguously in favor of this RFC.
-Voting cancelled 2014-08-13 15:35 UTC+
  
-===== Implementation =====+===== Changelog =====
  
-  * https://github.com/sgolemon/php-src/compare/switch.default.multiple +  * Vote opened (2014-08-12 16:50 UTC) 
- +  * Voting cancelled (2014-08-13 15:35 UTC) 
-Already landed in HHVM+  * Levi Morrison claims ownership of RFC (2014-08-14 17:13 UTC) 
-  * https://github.com/facebook/hhvm/commit/e77e2f74f9fd0619d5ae0555695d327af7dadffd+    * 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)
rfc/switch.default.multiple.1407944149.txt.gz · Last modified: 2017/09/22 13:28 (external edit)