1.2.640. Logical Operators Favorite

PHP has two sets of logical operators : letters (and, or, xor) and chars (&&, ||, ^).

The analyzed code has less than 10% of one of the two sets : for consistency reasons, it is recommended to make them all the same.

Warning : the two sets of operators have different precedence levels. Using and or && is not exactly the same, especially and not only, when assigning the results to a variable. Using and or && are also the target of other analysis.

<?php

$a1 = $b and $c;
$a1 = $b and $c;
$a1 = $b and $c;
$a1 = $b or $c;
$a1 = $b OR $c;
$a1 = $b and $c;
$a1 = $b and $c;
$a1 = $b and $c;
$a1 = $b or $c;
$a1 = $b OR $c;
$a1 = $b ^ $c;

?>

See also Logical Operators and Operators Precedence.

1.2.640.1. Suggestions

  • Pick a favorite, and enforce it

1.2.640.2. Specs

Short name

Php/LetterCharsLogicalFavorite

Rulesets

All, Changed Behavior, Preferences, Top10

Exakat since

0.12.4

PHP Version

All

Severity

Time To Fix

Precision

High

Features

logical-operator

Available in

Entreprise Edition, Exakat Cloud