Req #45906 [Com]: Cannot use square brackets on a function
| From: | php dot net at doppy dot nl | Date: | Tue, 20 Mar 2012 19:18:20 +0000 |
| Subject: | Req #45906 [Com]: Cannot use square brackets on a function | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-168661@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
Comment by: php dot net at doppy dot nl
Reported by: david dot c dot cook+php at gmail dot com
Summary: Cannot use square brackets on a function
Status: Open
Type: Feature/Change Request
Package: Feature/Change Request
PHP Version: 5.2.6
Block user comment: N
Private report: N
New Comment:
This is implemented in PHP 5.4.
This request can be closed.
Previous Comments:
------------------------------------------------------------------------
[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