1.2.56. Assigned In One Branch

This rule reports variables that are assigned in one branch, and not in the other.

This situation means that, depending on the branch used, some variables may not always be available. Such inbalance may generate warnings.

This rule looks at if/then structures.

<?php

if ($condition) {
    // $assigned_in_this_branch is assigned in only one of the branches
    $assigned_in_this_branch = 1;
    $also_assigned = 1;
} else {
    // $also_assigned is assigned in the two branches
    $also_assigned = 1;
}

?>

1.2.56.1. Connex PHP features

1.2.56.1.1. Suggestions

  • Assign in the second branch

  • Assign outside the condition

1.2.56.1.2. Specs

Short name

Structures/AssignedInOneBranch

Rulesets

All, Changed Behavior

Exakat since

1.0.5

PHP Version

All

Severity

Minor

Time To Fix

Quick (30 mins)

Precision

High

Available in

Entreprise Edition, Exakat Cloud