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
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
24 + 16 = ?
Subscribe to this entry?

 
 [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: Fri Apr 26 00:01:30 2024 UTC