#45906 [NEW]: Cannot use square brackets on a function

From: Date: Mon, 25 Aug 2008 02:35:54 +0000
Subject: #45906 [NEW]: Cannot use square brackets on a function
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-128372@lists.php.net to get a copy of this message
From: david dot c dot cook+php at gmail dot com Operating system: PHP version: 5.2.6 PHP Bug Type: Feature/Change Request Bug description: Cannot use square brackets on a function 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 bug report at http://bugs.php.net/?id=45906&edit=1 -- Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=45906&r=trysnapshot52 Try a CVS snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=45906&r=trysnapshot53 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=45906&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=45906&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=45906&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=45906&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=45906&r=needscript Try newer version: http://bugs.php.net/fix.php?id=45906&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=45906&r=support Expected behavior: http://bugs.php.net/fix.php?id=45906&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=45906&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=45906&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=45906&r=globals PHP 4 support discontinued: http://bugs.php.net/fix.php?id=45906&r=php4 Daylight Savings: http://bugs.php.net/fix.php?id=45906&r=dst IIS Stability: http://bugs.php.net/fix.php?id=45906&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=45906&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=45906&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=45906&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=45906&r=mysqlcfg

« previous php.bugs (#128372) next »