Pattern: Assignment in condition
Issue: -
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 of incorrect code:
if ($test = 'abc') {
do_something();
}
Example of correct code:
if ($test === 'abc') {
do_something();
}