|  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
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
 [2008-08-25 02:35 UTC] david dot c dot cook+php at gmail dot com
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'); 

echo test()[0];

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

Expected result:

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


Add a Patch

Pull Requests

Add a Pull Request


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]
Good catch; thanks.
 [2012-03-21 00:51 UTC]
-Status: Open +Status: Closed -Package: Feature/Change Request +Package: *General Issues -Assigned To: +Assigned To: felipe
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Tue Feb 07 04:05:50 2023 UTC