1.2.856. Not Equal Is Not !==

Not and Equal operators, used separately, don’t amount to the different operator !==.

!$a == $b first turns $a``into the opposite boolean, then compares this boolean value to ``$b. On the other hand, $a !== $b compares the two variables for type and value, and returns a boolean. Note that the instanceof operator may be use with this syntax, due to operator precedence.

<?php

if ($string != 'abc') {
    // doSomething()
}

// Here, string will be an boolean, leading
if (!$string == 'abc') {
    // doSomething()
}

// operator priority may be confusing
if (!$object instanceof OneClass) {
    // doSomething()
}
?>

See also Operator Precedence.

1.2.856.1. Suggestions

  • Use the != or !==

  • Use parenthesis

1.2.856.2. Specs

Short name

Structures/NotEqual

Rulesets

All, Analyze, CE, CI-checks

Exakat since

2.0.6

PHP Version

All

Severity

Minor

Time To Fix

Quick (30 mins)

Precision

Very high

Features

comparison

Available in

Entreprise Edition, Community Edition, Exakat Cloud