1.2.702. 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.702.1. Suggestions

  • Use parenthesis to show intent in the addition expression

1.2.702.2. Specs

Short name

Structures/MissingParenthesis

Rulesets

All, Analyze, CE, CI-checks, Changed Behavior

Exakat since

1.2.6

PHP Version

All

Severity

Major

Time To Fix

Instant (5 mins)

Precision

High

Features

parenthesis, readability

Available in

Entreprise Edition, Community Edition, Exakat Cloud