php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #38723 Use parentheses when returning an expression... *everything* is an expression!
Submitted: 2006-09-05 13:24 UTC Modified: 2006-09-06 12:43 UTC
From: z_rules55 at hotmail dot com Assigned: colder (profile)
Status: Closed Package: Documentation problem
PHP Version: Irrelevant OS:
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: z_rules55 at hotmail dot com
New email:
PHP Version: OS:

 

 [2006-09-05 13:24 UTC] z_rules55 at hotmail dot com
Description:
------------
The docs section on "return" (http://us3.php.net/manual/en/function.return.php) states that:
"Note that since return() is a language construct and not a function, the parentheses surrounding its arguments are only required if the argument contains an expression. It is common to leave them out while returning a variable, and you actually should as PHP has less work to do in this case."

But the docs on what an expression *is* (http://us3.php.net/manual/en/language.expressions.php) say that:
"In PHP, almost anything you write is an expression. The simplest yet most accurate way to define an expression is "anything that has a value"."
And then goes on to say that the literal '5' is an expression. It's confusing.

What, then, is an expression in PHP? If parentheses are required when returning the value of an expression, does that mean an expression as in a calculation (return (1 + 2)), or an assignment (return ($GLOBALS['a'] = $b)), or a function call (return (funky_function())), or what?


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-09-06 12:43 UTC] colder@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.

Parentheses are in fact not required at all in that case.
 [2020-02-07 06:11 UTC] phpdocbot@php.net
Automatic comment on behalf of colder
Revision: http://git.php.net/?p=doc/en.git;a=commit;h=b6359ff0b653c8d2fcf4784949ebb52c77d15eb7
Log: Fix #38723 (Parentheses are not required)
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Tue Jul 08 17:01:35 2025 UTC