From: php at bucksvsbytes dot com
Operating system: RHEL 3.1
PHP version: Irrelevant
PHP Bug Type: Unknown/Other Function
Bug description: explode yields an array, but appending a key causes syntax error
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 bug report at http://bugs.php.net/?id=29305&edit=1
--
Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=29305&r=trysnapshot4
Try a CVS snapshot (php5): http://bugs.php.net/fix.php?id=29305&r=trysnapshot5
Fixed in CVS: http://bugs.php.net/fix.php?id=29305&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=29305&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=29305&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=29305&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=29305&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=29305&r=support
Expected behavior: http://bugs.php.net/fix.php?id=29305&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=29305&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=29305&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=29305&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=29305&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=29305&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=29305&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=29305&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=29305&r=float