website/errors/booleanOr.rightAlwaysFalse.md
<?php declare(strict_types = 1);
function doFoo(int $i): void
{
$f = false;
if ($i > 0 || $f) {
echo 'right always false';
}
}
The right side of the || operator always evaluates to false. This means the right operand never contributes to the condition -- the result depends solely on the left side. This usually indicates redundant logic, a copy-paste mistake, or a condition that has been made unnecessary.
In the example above, $f is always false, so the right side of || is redundant and the entire condition is equivalent to just $i > 0.
Remove the redundant right-side condition:
<?php declare(strict_types = 1);
function doFoo(int $i): void
{
- $f = false;
- if ($i > 0 || $f) {
+ if ($i > 0) {
echo 'right always false';
}
}
Or fix the right side to use a meaningful condition:
<?php declare(strict_types = 1);
-function doFoo(int $i): void
+function doFoo(int $i, bool $flag): void
{
- $f = false;
- if ($i > 0 || $f) {
+ if ($i > 0 || $flag) {
// ...
}
}