1.2.1352. Use The Case Value¶
When switch() has branched to the right case, the value of the switched variable is known : it is the case.
This doesn’t work with complex expression cases, nor with default.
<?php
switch($a) {
case 'a' :
// $a == 'a';
echo $a;
break;
case 'b' :
// $a == 'b';
echo 'b';
break;
}
?>
1.2.1352.1. Suggestions¶
Use the literal value in the case, to avoid unnecessary computation.
1.2.1352.2. Specs¶
Short name |
Structures/UseCaseValue |
Rulesets |
|
Exakat since |
1.9.6 |
PHP Version |
All |
Severity |
Minor |
Time To Fix |
Quick (30 mins) |
Precision |
Very high |
Available in |