php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #29305 explode yields an array, but appending a key causes syntax error
Submitted: 2004-07-21 16:19 UTC Modified: 2004-07-21 16:25 UTC
From: php at bucksvsbytes dot com Assigned:
Status: Not a bug Package: Unknown/Other Function
PHP Version: Irrelevant OS: RHEL 3.1
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: php at bucksvsbytes dot com
New email:
PHP Version: OS:

 

 [2004-07-21 16:19 UTC] 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

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-07-21 16:25 UTC] tony2001@php.net
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


 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Jul 02 15:01:34 2025 UTC