php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #49346 using return() with an empty argument list is causing in a parser error
Submitted: 2009-08-24 15:20 UTC Modified: 2009-08-26 06:00 UTC
From: mirko dot steiner at slashdevslashnull dot de Assigned:
Status: Closed Package: Documentation problem
PHP Version: 5.2.10 OS: linux, freebsd
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: mirko dot steiner at slashdevslashnull dot de
New email:
PHP Version: OS:

 

 [2009-08-24 15:20 UTC] mirko dot steiner at slashdevslashnull dot de
Description:
------------
using return() with an empty argument list is causing in a parser error.

Reproduce code:
---------------
<?php
function foo($arg) {
    if($arg) {
        return('bar');
    } else {
        return();
    }
}
?>


Expected result:
----------------
no parser error :-)

Actual result:
--------------
Parse error: syntax error, unexpected ')' in 
/usr/local/www/develop/htdocs/test.php on line 6

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-08-24 18:08 UTC] sjoerd@php.net
Thank you for your report.

The behavior you report is not a bug. You call return as if it is a function. It is not, it is a language construct.

The correct syntax is:
return 'bar';
or
return;

The parenthesis are not needed.
 [2009-08-24 18:59 UTC] mirko dot steiner at slashdevslashnull dot de
thank you, for your immidiatly response.

yes, i know that ,,return'' is a language construct. it is documented that the parentheses are not required (1) but not 
that it is necessary that there have to be an argument if the parantheses are used.

using ,,echo()'' for example, which is a function(!), brings the same parser error when using empty parentheses.

it seems like an error in the parser where functions or ,,language constructs'' where the parantheses are optional.

(1) http://de2.php.net/manual/en/function.return.php (requested Mon Aug 24 20:45:38 CEST 2009)
 [2009-08-25 07:14 UTC] sjoerd@php.net
I agree that the documentation suggests that return() is valid, because it refers to the return statement as "return()". Maybe "return" without parenthesis would be better.

Note that echo() is also a language construct and not a function. I change this bug to category "Documentation", so that the documentation return and echo can be clarified.
 [2009-08-25 12:48 UTC] mirko dot steiner at slashdevslashnull dot de
first of all, i was wrong. echo (1) is listed under ,,string functions'' but is documented as a language construct.

I don't want to start a discussion here about ,,what is a function and what is a language construct'', in my opinion it is just a inconsistence in the PHP language that the parantheses for return are optional because it is a language construct.
how ever, for me as a programmer, its easier to handle everything as a function not to difference between a ,,language construct'' and a function: functioname (arg1[, arg2] ...)
the parantheses are optional, its for me not a feature, its a inconsistence, so is the parser error if no argument is given in case i use a language construct instead of a function.
if it is possible to use parantheses, and i use them, they should have the expected parantheses behavior.
just my two cents.

 (1) http://de3.php.net/manual/en/function.echo.php (requested Tue Aug 25 14:33:40 CEST 2009)
 [2009-08-26 05:59 UTC] svn@php.net
Automatic comment from SVN on behalf of torben
Revision: http://svn.php.net/viewvc/?view=revision&revision=287728
Log: Clarified what will happen if you call return using parentheses but no argument.
Addresses Bug #49346.
Note: perhaps control structure documentation should be normalized to cover this sort of thing.
 [2009-08-26 06:00 UTC] torben@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.


 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Fri Aug 01 12:00:03 2025 UTC