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
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: 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: Mon Dec 02 17:01:35 2024 UTC