php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #62449 Allow comma separated statements with (brace omitted) if statements
Submitted: 2012-06-29 13:38 UTC Modified: 2012-06-29 14:17 UTC
From: andrew at phantom dot uk dot net Assigned:
Status: Closed Package: *General Issues
PHP Version: 5.4.4 OS:
Private report: No CVE-ID: None
 [2012-06-29 13:38 UTC] andrew at phantom dot uk dot net
Description:
------------
Allow statements to be separated by commas in single line if statements (when 
omitting the braces)

Test script:
---------------
if ( isset($_GET['take_me_there']) )
   header('location: /you_are_here.php'), exit;


Expected result:
----------------
The client would be redirected to www.yoursite.com/you_are_here.php and the 
script would terminate execution.

Actual result:
--------------
Parse error: syntax error, unexpected ',' in /opt/lampp/htdocs/test.php on line 2

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-06-29 14:08 UTC] johannes@php.net
-Status: Open +Status: No Feedback
 [2012-06-29 14:08 UTC] johannes@php.net
This leads to too many conflicts. For instance what should this code do:

    if (condition()) echo foo(), bar();

right now it prints the returned values from foo() and bar(). This can't be easily distinguished from your syntax. There are other similar cases. Such special case syntax also makes the language more complex with more special cases to mind.
 [2012-06-29 14:10 UTC] phpmpan at mpan dot pl
if ($foo)
  echo 'bar', throw $foo;

What should be the meaning of this code?
 [2012-06-29 14:17 UTC] andrew at phantom dot uk dot net
@johannes
Yeah, someone pointed that out to me in #phpnw right after I posted this.
@phpmpan
Assuming $foo is an instance of Exception, it would echo 'bar' then throw an 
exception, in my original though process, however someone pointed out to me that 
some language constructs (such as echo) already allow a comma separated list of 
arguments.

Although, in that case the comma is not immediately followed by a variable that 
can be converted to string, so I don't think that's as good a demonstration of 
the issue at hand as johannes example.

It could work if the statements were separated by say, a colon, but this is 
probably over-complicating things for a simple convenience.
 [2012-06-29 14:17 UTC] andrew at phantom dot uk dot net
-Status: No Feedback +Status: Closed
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri May 03 21:01:32 2024 UTC