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