PHP

PHP

By DeepSource

Function comparison is always positivePHP-W1089

Bug risk

PHP functions such as count(), strlen(), and abs() always returns positive value. So, checking that function's return value is greater than or equal to zero doesn't make sense since the expression will always evaluate to true. In addition, checking that value is less than zero will always evaluate to false.

If intention was to check for non-emptiness use empty() function or check if value is greater than zero.

Example

Bad practice

if (count($value) >= 0) { // `count()` will always be greater than or equal to zero
    // some implementation here
}
if (strlen($xml) < 0) { // `strlen()` will never be less than zero, so implementation inside the condition will never be executed
    // some implementation here
}

Recommended

if (count($value) > 0) {
    // some implementation here
}
if (empty($xml)) {
    // some implementation here
}