|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #42129 restrict explode's function return type
Submitted: 2007-07-27 22:01 UTC Modified: 2014-12-31 16:24 UTC
Avg. Score:4.3 ± 0.9
Reproduced:2 of 2 (100.0%)
Same Version:0 (0.0%)
Same OS:1 (50.0%)
From: david dot nqd at gmail dot com Assigned:
Status: Open Package: *General Issues
PHP Version: 5.2.3 OS: Irrelevant
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2007-07-27 22:01 UTC] david dot nqd at gmail dot com
This is not a bug report like #38337.

Shouldn't the return type of explode be restricted to an array given valid inputs (strings)?
This would mean that if an empty string was passed as the delimiter, the return would be an array containing individual characters.

I doubt this would break any existing code unless people used explode to check that the delimiter === ''

Reproduce code:
$x = explode('', 'abc');

Expected result:
$x = array('a','b','c')

Actual result:
$x = false


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2012-07-19 14:52 UTC] alastair at propcom dot co dot uk
This affects me too.

I don't want this to be my string-split paradigm:

if ($delimiter === '') return str_split($str);
else return explode($delimiter, $str);

That's just stupid. Splitting on the empty string is a completely logical and 
well-defined operation.
 [2014-12-31 16:24 UTC]
-Package: Feature/Change Request +Package: *General Issues
 [2014-12-31 16:24 UTC]
Note that if explode('', 'abc') were implemented the correct result would actually be array('', 'a', 'b', 'c', ''), which would be unexpected to many people. To avoid confusion PHP does not allow this usage.
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Mon Sep 28 13:01:23 2020 UTC