Skip to content

Files

Latest commit

 

History

History
29 lines (19 loc) · 661 Bytes

Generic.CodeAnalysis.AssignmentInCondition.md

File metadata and controls

29 lines (19 loc) · 661 Bytes

Pattern: Assignment in condition

Issue: -

Description

Assignments in conditionals are often typos: for example if (var1 = var2) instead of if (var1 == var2). They also can be an indicator of overly clever code which decreases maintainability.

Example

Example of incorrect code:

if ($test = 'abc') {
    do_something();
}

Example of correct code:

if ($test === 'abc') {
    do_something();
}

Further Reading