Req #45906 [Opn->Csd]: Cannot use square brackets on a function
| From: | aharvey@php.net | Date: | Wed, 21 Mar 2012 00:51:08 +0000 |
| Subject: | Req #45906 [Opn->Csd]: Cannot use square brackets on a function | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-168673@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=45906&edit=1
ID: 45906
Updated by: aharvey@php.net
Reported by: david dot c dot cook+php at gmail dot com
Summary: Cannot use square brackets on a function
-Status: Open
+Status: Closed
Type: Feature/Change Request
-Package: Feature/Change Request
+Package: *General Issues
PHP Version: 5.2.6
-Assigned To:
+Assigned To: felipe
Block user comment: N
Private report: N
New Comment:
Good catch; thanks.
Previous Comments:
------------------------------------------------------------------------
[2012-03-20 19:18:20] php dot net at doppy dot nl
This is implemented in PHP 5.4.
This request can be closed.
------------------------------------------------------------------------
[2008-08-25 02:35:53] 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 '['
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=45906&edit=1