1.2.966. Parenthesis As Parameter¶
Using parenthesis around parameters used to silent some internal check. This is not the case anymore in PHP 7, and should be fixed by removing the parenthesis and making the value a real reference.
<?php
// example extracted from the PHP manual
function getArray() {
return [1, 2, 3];
}
function squareArray(array &$a) {
foreach ($a as &$v) {
$v \*\*\= 2;
}
}
// Generates a warning in PHP 7.
squareArray((getArray()));
?>
See also Parentheses around function arguments no longer affect behaviour.
1.2.966.2. Connex PHP features¶
1.2.966.2.1. Suggestions¶
Remove the parenthesis when they are only encapsulating an argument
Replace the parenthesis by the no-scream operator
1.2.966.2.2. Specs¶
Short name |
Php/ParenthesisAsParameter |
Rulesets |
All, Changed Behavior, CompatibilityPHP53, CompatibilityPHP54, CompatibilityPHP55, CompatibilityPHP56 |
Exakat since |
0.8.4 |
PHP Version |
With PHP 7.0 and older |
Severity |
Major |
Time To Fix |
Quick (30 mins) |
Precision |
Very high |
Available in |