php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #45906 Cannot use square brackets on a function
Submitted: 2008-08-25 02:35 UTC Modified: 2012-03-21 00:51 UTC
Votes:15
Avg. Score:4.0 ± 1.4
Reproduced:12 of 12 (100.0%)
Same Version:5 (41.7%)
Same OS:4 (33.3%)
From: david dot c dot cook+php at gmail dot com Assigned: felipe (profile)
Status: Closed Package: *General Issues
PHP Version: 5.2.6 OS:
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: david dot c dot cook+php at gmail dot com
New email:
PHP Version: OS:

 

 [2008-08-25 02:35 UTC] david dot c dot cook+php at gmail dot com
Description:
------------
Cannot use square brackets to directly reference array elements in the returned value of a function. As a flexible language that can do pretty much anything, it seems logical to be able to achieve this on one line, without having to first assign the return value to a temporary variable.

Reproduce code:
---------------
function test()
{ 
   return array('a', 'b'); 
}

//desired
echo test()[0];

//workaround
//$temp = test();
//echo $temp[0];

Expected result:
----------------
a

Actual result:
--------------
Parse error: syntax error, unexpected '['

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-03-20 19:18 UTC] php dot net at doppy dot nl
This is implemented in PHP 5.4.
This request can be closed.
 [2012-03-21 00:51 UTC] aharvey@php.net
Good catch; thanks.
 [2012-03-21 00:51 UTC] aharvey@php.net
-Status: Open +Status: Closed -Package: Feature/Change Request +Package: *General Issues -Assigned To: +Assigned To: felipe
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 06:01:35 2024 UTC