Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Warn if continue is used on switch
Supersedes RFC https://wiki.php.net/rfc/continue_on_switch_deprecation by generating a warning instead of deprecating and removing this functionality.
- Loading branch information
Showing
with
94 additions
and 6 deletions.
- +13 −0 UPGRADING
- +49 −0 Zend/tests/continue_targeting_switch_warning.phpt
- +31 −6 Zend/zend_compile.c
- +1 −0 Zend/zend_compile.h
@@ -0,0 +1,49 @@ | ||
--TEST-- | ||
Warning on continue targeting switch | ||
--FILE-- | ||
<?php | ||
|
||
function test() { | ||
switch ($foo) { | ||
case 0: | ||
continue; // INVALID | ||
case 1: | ||
break; | ||
} | ||
|
||
while ($foo) { | ||
switch ($bar) { | ||
case 0: | ||
continue; // INVALID | ||
case 1: | ||
continue 2; | ||
case 2: | ||
break; | ||
} | ||
} | ||
|
||
while ($foo) { | ||
switch ($bar) { | ||
case 0: | ||
while ($xyz) { | ||
continue 2; // INVALID | ||
} | ||
case 1: | ||
while ($xyz) { | ||
continue 3; | ||
} | ||
case 2: | ||
while ($xyz) { | ||
break 2; | ||
} | ||
} | ||
} | ||
} | ||
|
||
?> | ||
--EXPECTF-- | ||
Warning: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? in %s on line 6 | ||
|
||
Warning: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? in %s on line 14 | ||
|
||
Warning: "continue 2" targeting switch is equivalent to "break 2". Did you mean to use "continue 3"? in %s on line 26 |
@nikic Shouldn't this be
E_COMPILE_WARNING
instead ofE_WARNING
?