1.2.1055. Return With Parenthesis¶
return statement doesn’t require parenthesis. PHP tolerates them with return statement, but it is recommended not to use them.
From the PHP Manual : ‘Note: Note that since return is a language construct and not a function, the parentheses surrounding its argument are not required and their use is discouraged.’.
<?php
function foo() {
$a = rand(0, 10);
// No need for parenthesis
return $a;
// Parenthesis are useless here
return ($a);
// Parenthesis are useful here: they are needed by the multplication.
return ($a + 1) * 3;
}
?>
See also PHP return(value); vs return value; and return.
1.2.1055.1. Connex PHP features¶
1.2.1055.1.1. Suggestions¶
Remove the parenthesis
1.2.1055.1.2. Specs¶
Short name |
Php/ReturnWithParenthesis |
Rulesets |
All, Changed Behavior, Coding conventions, PHP recommendations, Suggestions |
Exakat since |
0.8.4 |
PHP Version |
All |
Severity |
Minor |
Time To Fix |
Instant (5 mins) |
Precision |
High |
Available in |