php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #30095 explode on an empty string creates non-empty array
Submitted: 2004-09-15 16:42 UTC Modified: 2004-09-17 04:43 UTC
From: billmarrs at gmail dot com Assigned:
Status: Not a bug Package: *General Issues
PHP Version: 5.0.0 OS: Linux
Private report: No CVE-ID: None
 [2004-09-15 16:42 UTC] billmarrs at gmail dot com
Description:
------------
explode on an empty string creates an array with a single blank element, instead of an empty array (with no elements).

This means that explode/implode do not yield reversible results when an empty array is used (though, they do otherwise -- when the array is non-empty).

This is a duplicate of #699, but I'm resubmitting since #699 was closed with no explanation a long time ago.

Reproduce code:
---------------
$a = array();

$b = explode(":", implode(":", $a));

print "a: ";
print_r($a);

print "<p>b: ";
print_r($b);

Expected result:
----------------
a: Array ( ) 
b: Array ( ) 



Actual result:
--------------
a: Array ( ) 
b: Array ( [0] => ) 

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-09-17 04:43 UTC] iliaa@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

When you explode a string even if the separator string was 
not found the output will still be an array. This array 
will contain a single element, which will contain the 
entire string. This is '' in your case. 
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Oct 17 18:01:29 2024 UTC