1.2.1343. 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.1343.1. Suggestions

  • Use the literal value in the case, to avoid unnecessary computation.

1.2.1343.2. Specs

Short name

Structures/UseCaseValue

Rulesets

All, Changed Behavior, Suggestions

Exakat since

1.9.6

PHP Version

All

Severity

Minor

Time To Fix

Quick (30 mins)

Precision

Very high

Available in

Entreprise Edition, Exakat Cloud