rfc:continue_on_switch_deprecation

Differences

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

Link to this comparison view

Next revision
Previous revision
rfc:continue_on_switch_deprecation [2018/06/24 15:33] – created nikicrfc:continue_on_switch_deprecation [2018/07/07 09:18] (current) – Mark as withdrawn nikic
Line 3: Line 3:
   * Author: Nikita Popov <nikic@php.net>   * Author: Nikita Popov <nikic@php.net>
   * Implementation: https://github.com/php/php-src/pull/3323   * Implementation: https://github.com/php/php-src/pull/3323
-  * Status: Under Discussion+  * Status: Withdrawn 
 + 
 +**Based on the RFC discussion, we decided to instead implement this as a simple warning, which has happened in https://github.com/php/php-src/pull/3364.**
  
 ===== Introduction ===== ===== Introduction =====
Line 16: Line 18:
         case "baz":         case "baz":
             continue; // In PHP: Behaves like "break;"             continue; // In PHP: Behaves like "break;"
-                      // In C: Behaves like "continue 2;"+                      // In C:   Behaves like "continue 2;"
     }     }
 } }
Line 27: Line 29:
 This RFC proposes to deprecate in PHP 7.3 and remove in PHP 8 the ability to target a switch statement through continue. This is no loss in functionality (it is always possible to replace the continue with a break), but avoids a gotcha for programmers coming from other languages. This RFC proposes to deprecate in PHP 7.3 and remove in PHP 8 the ability to target a switch statement through continue. This is no loss in functionality (it is always possible to replace the continue with a break), but avoids a gotcha for programmers coming from other languages.
  
-The following illustrates cases which are deprecated and by what they can be replaced at various levels of loop nesting:+The following code illustrates cases which are deprecated and by what they can be replaced at various levels of loop nesting:
  
 <code php> <code php>
Line 63: Line 65:
 ===== Unaffected PHP Functionality ===== ===== Unaffected PHP Functionality =====
  
-Continue can still be used inside switch statements, as long as it does not target the switch.+Continue can still be used inside switch statements, as long as it does not target the switch. The meaning of continue and break inside switch never changes, some cases are just forbidden. 
 + 
 +To further clarify which uses of ''continue'' are affected, please consider the following example: 
 + 
 +<code php> 
 +while ($foo) { 
 +    switch ($bar) { 
 +        case "baz": 
 +            while ($xyz) { 
 +                continue;   // Targeting the inner while loop: Allowed 
 +                continue 2; // Targeting the switch: Deprecated 
 +                continue 3; // Targeting the outer while loop: Allowed 
 +            } 
 +    } 
 +
 +</code>
  
 ===== Vote ===== ===== Vote =====
  
 As this is a language change, a 2/3 majority is required. As this is a language change, a 2/3 majority is required.
rfc/continue_on_switch_deprecation.txt · Last modified: 2018/07/07 09:18 by nikic