1.2.707. Missing Parenthesis¶
Adding parenthesis to addition expressions make them more readable and to prevent bugs.
In the expressions below, the code is legit, although it is prone to misunderstanding.
<?php
// Missing some parenthesis!!
if (!$a instanceof Stdclass) {
print "Not\n";
} else {
print "Is\n";
}
// Could this addition be actually,
$c = -$a + $b;
// this one ?
$c = -($a + $b);
// or this one ?
$c = $b - $a;
?>
See also Operators Precedence.
1.2.707.1. Connex PHP features¶
1.2.707.1.1. Suggestions¶
Use parenthesis to show intent in the addition expression
1.2.707.1.2. Specs¶
Short name |
Structures/MissingParenthesis |
Rulesets |
|
Exakat since |
1.2.6 |
PHP Version |
All |
Severity |
Major |
Time To Fix |
Instant (5 mins) |
Precision |
High |
Available in |