website/errors/booleanAnd.alwaysFalse.md
<?php declare(strict_types = 1);
function doFoo(int $i): void
{
$result = $i > 5 && $i < 3;
}
The result of the && (boolean AND) expression always evaluates to false. This happens when it is impossible for both sides of the operator to be truthy at the same time. In the example above, $i cannot be both greater than 5 and less than 3 simultaneously, so the entire expression is always false. This usually indicates a logic error or dead code.
Fix the logic so that both conditions can be satisfied:
<?php declare(strict_types = 1);
function doFoo(int $i): void
{
- $result = $i > 5 && $i < 3;
+ $result = $i > 3 && $i < 5;
}
Or remove the expression entirely if the code block is unreachable:
<?php declare(strict_types = 1);
function doFoo(int $i): void
{
- $result = $i > 5 && $i < 3;
}