Skip to content
PHP Logo

Why should parentheses not be used around the return statement in a PHP function?

Using parentheses around the return statement in a PHP function is unnecessary and can lead to confusion or syntax errors. The return statement itself is a language construct and does not require parentheses to function properly. To avoid any potential issues, it is best practice to omit the parentheses when using the return statement in a PHP function.

php
// Incorrect usage of parentheses around the return statement
function addNumbers($a, $b) {
    return ($a + $b); // Incorrect usage of parentheses
}

// Correct implementation without parentheses around the return statement
function addNumbers($a, $b) {
    return $a + $b; // Correct implementation without parentheses
}