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 Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
43 + 47 = ?
Subscribe to this entry?

 
 [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

Add a Patch

Pull Requests

Add a Pull Request

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 Apr 25 04:01:38 2024 UTC