1.2.1174. Suspicious Comparison

The comparison seems to be misplaced.

A comparison happens in the last argument, while the actual function expect another type : this may be the case of a badly placed parenthesis. Original idea by Vladimir Reznichenko.

<?php

// trim expect a string, a boolean is given.
if (trim($str === '')){

}

// Just move the first closing parenthesis to give back its actual meaning
if (trim($str) === ''){

}

?>

1.2.1174.1. Suggestions

  • Remove the comparison altogether

  • Move the comparison to its right place : that, or more the parenthesis.

  • This may be what is intended : just leave it.

1.2.1174.2. Specs

Short name

Structures/SuspiciousComparison

Rulesets

All, Analyze

Exakat since

0.11.0

PHP Version

All

Severity

Major

Time To Fix

Instant (5 mins)

Precision

Very high

Features

comparison

Examples

PhpIPAM, ExpressionEngine

Available in

Entreprise Edition, Exakat Cloud