1.2.862. 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.862.1. Connex PHP features¶
1.2.862.1.1. Suggestions¶
Use the != or !==
Use parenthesis
1.2.862.1.2. Specs¶
Short name |
Structures/NotEqual |
Rulesets |
|
Exakat since |
2.0.6 |
PHP Version |
All |
Severity |
Minor |
Time To Fix |
Quick (30 mins) |
Precision |
Very high |
Available in |