website/errors/logicalXor.rightAlwaysFalse.md
<?php declare(strict_types = 1);
function doFoo(bool $flag): bool
{
$f = false;
return $flag xor $f;
}
The right side of the xor operator always evaluates to false. This makes the xor expression equivalent to just the left side, because $left xor false always equals $left. The right operand is redundant and likely indicates a logic error.
In the example above, $f is always false, so $flag xor $f is equivalent to $flag.
Simplify the expression by removing the redundant xor:
<?php declare(strict_types = 1);
function doFoo(bool $flag): bool
{
- $f = false;
- return $flag xor $f;
+ return $flag;
}
Or fix the right-side condition so that it can actually evaluate to true:
<?php declare(strict_types = 1);
-function doFoo(bool $flag): bool
+function doFoo(bool $flag, bool $other): bool
{
- $f = false;
- return $flag xor $f;
+ return $flag xor $other;
}