#29305 [Opn->Bgs]: explode yields an array, but appending a key causes syntax error

From: Date: Wed, 21 Jul 2004 14:25:43 +0000
Subject: #29305 [Opn->Bgs]: explode yields an array, but appending a key causes syntax error
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-63258@lists.php.net to get a copy of this message
ID: 29305 Updated by: tony2001@php.net Reported By: php at bucksvsbytes dot com -Status: Open +Status: Bogus Bug Type: Unknown/Other Function Operating System: RHEL 3.1 PHP Version: Irrelevant New Comment: Thank you for taking the time to write to us, but this is not a bug. Please double-check the documentation available at http://www.php.net/manual/ and the instructions on how to report a bug at http://bugs.php.net/how-to-report.php Previous Comments: ------------------------------------------------------------------------ [2004-07-21 16:19:35] php at bucksvsbytes dot com Description: ------------ This bug applies at least through 4.3.2. Sorry about version, but I'm restricted to using rpm's, which means I can never get near the current version. If this disqualifies me from ever reporting bugs, please advise and I will stop. The explode function yields an array result, so you would expect the following statement to be syntactically correct: $result=explode($separator,$string)[$key]; However, that syntax yields a "parse error". The workaround is to assign explode to a variable first: $array=explode($separator,$string); $result=$array[$key]; Reproduce code: --------------- $result=explode(':','a:b:c')[0]; Expected result: ---------------- $result gets 'a' Actual result: -------------- Parse error: parse error ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=29305&edit=1

« previous php.bugs (#63258) next »