When either the equality operator in a null test or the logical operator that follows it is reversed, the code has the appearance of safely null-testing the object before dereferencing it. Unfortunately the effect is just the opposite - the object is null-tested and then dereferenced only if it is null, leading to a guaranteed null pointer dereference.

Noncompliant Code Example

if ($obj == null && $obj->isOpen()) {
  echo "Object is open";
}

if ($obj != null || $obj->isOpen()) {
  echo "Object is not open";
}

Compliant Solution

if ($obj == null || $obj->isOpen()) {
  echo "Object is open";
}

if ($obj != null && !$obj->isOpen()) {
  echo "Object is not open";
}