1.2.1187. Switch With Too Many Default¶
Switch statements should only hold one default, not more. Check the code and remove the extra default.
PHP 7.0 won’t compile a script that allows for several default cases.
Multiple default happens often with large switch().
<?php
switch($a) {
case 1 :
break;
default :
break;
case 2 :
break;
default : // This default is never reached
break;
}
?>
1.2.1187.1. Connex PHP features¶
1.2.1187.1.1. Suggestions¶
Remove the useless default : it may be the first, or the last. In case of ambiguity, keep the first, as it is the one being used at the moment.
1.2.1187.1.2. Specs¶
Short name |
Structures/SwitchWithMultipleDefault |
Rulesets |
All, Changed Behavior, CompatibilityPHP53, CompatibilityPHP54, CompatibilityPHP55, CompatibilityPHP56 |
Exakat since |
0.8.4 |
PHP Version |
With PHP 7.0 and older |
Severity |
Minor |
Time To Fix |
Quick (30 mins) |
Precision |
Very high |
Available in |