Edit report at https://bugs.php.net/bug.php?id=45906&edit=1

 ID:                 45906
 Updated by:         ahar...@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

Reply via email to