website/errors/booleanAnd.alwaysTrue.md
<?php declare(strict_types = 1);
/** @param positive-int $i */
function doFoo(int $i): void
{
if ($i > 0 && is_int($i)) {
echo 'always';
}
}
The result of the && (boolean AND) expression always evaluates to true. This happens when both sides of the operator are always truthy, making the condition constant. In this example, $i is a positive-int, so $i > 0 is always true and is_int($i) is also always true. This usually indicates a logic error, a redundant check, or dead code.
Remove the redundant condition if the check is unnecessary:
<?php declare(strict_types = 1);
/** @param positive-int $i */
function doFoo(int $i): void
{
- if ($i > 0 && is_int($i)) {
- echo 'always';
- }
+ echo 'always';
}
Or fix the logic to use conditions that are meaningful:
<?php declare(strict_types = 1);
/** @param positive-int $i */
function doFoo(int $i): void
{
- if ($i > 0 && is_int($i)) {
+ if ($i > 0 && $i < 100) {
echo 'always';
}
}