php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #7076 Incosistence between explode and implode
Submitted: 2000-10-07 03:47 UTC Modified: 2000-10-07 06:01 UTC
From: v at w dot cl Assigned:
Status: Closed Package: *Function Specific
PHP Version: 4.0.3RC2 OS: RedHat 6.2
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: v at w dot cl
New email:
PHP Version: OS:

 

 [2000-10-07 03:47 UTC] v at w dot cl
Implode and explode can behave differently.

I can write 

$a=implode($array,"|");

and $a would be the expected string separated by |.

But if I write 

$array=explode($a,"|");

$array would NOT be the original $array, but an empty value.

And neither implode or explode throws a warning about the bad parameter passing.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2000-10-07 06:01 UTC] torben@php.net
This is actually the correct behaviour. 
 
implode() can accept its two arguments in any order: the array first, 
or the string. This is possible because it can examine each argument 
to discern which is which based on type. explode() can't do that, 
since it can accept only strings. Essentially, by writing 'explode($a, 
"|")', you are telling PHP to split the string "|" on each occurrence 
of $a within it. To us this is obviously likely to not be what you 
wanted, but to PHP it makes sense--it trusts that this is what you 
want to do, and so it tries it and returns the result: an array 
containing only "|". 
 
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Oct 31 23:01:28 2024 UTC