1.2.641. Logical Should Use Symbolic Operators¶
Logical operators come in two flavors : and / &&, || / or, ^ / xor. However, they are not exchangeable, as && and and have different precedence.
It is recommended to use the symbol operators, rather than the letter ones.
<?php
// Avoid lettered operator, as they have lower priority than expected
$a = $b and $c;
// $a === 3 because equivalent to ($a = $b) and $c;
// safe way to write the above :
$a = ($b and $c);
$a = $b && $c;
// $a === 1
?>
See also Logical Operators.
1.2.641.1. Suggestions¶
Change the letter operators to the symbol one : and => &&, or => ||, xor => ^. Review the new expressions as processing order may have changed.
Add parenthesis to make sure that the order is the expected one
1.2.641.2. Specs¶
Short name |
Php/LogicalInLetters |
Rulesets |
All, Analyze, CE, CI-checks, Suggestions, Top10, php-cs-fixable |
Exakat since |
0.8.4 |
PHP Version |
All |
Severity |
Minor |
Time To Fix |
Instant (5 mins) |
Precision |
Very high |
Features |
logical |
ClearPHP |
|
Examples |
|
Available in |