php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #1932 implode() changes array contents
Submitted: 1999-07-30 14:10 UTC Modified: 1999-07-30 18:35 UTC
From: alan at gocdo dot net dot au Assigned:
Status: Closed Package: Misbehaving function
PHP Version: 4.0 Latest CVS (30/07/1999) OS: Red Hat 5.2
Private report: No CVE-ID: None
 [1999-07-30 14:10 UTC] alan at gocdo dot net dot au
Complied as cgi binary.
When implode is passed an array with an element that contains an array the contents of the contained array  is lost.. eg.

 <?php

$tmp=  array ( array(   "x"=>"first_item",
                        "y"=>"second_Item",
                        "z"=>"third_item"
                        )
                );
$cpy=$tmp;

// echo "size at start ".sizeof($tmp[0])."<BR>";
echo "1st implode call: ".implode($cpy,"+")."<BR>";
echo "2nd implode call: ".implode($tmp[0],"+")."<BR>";
echo "size at end ".sizeof($tmp[0])."<BR>";  
?>
             
gives the following output:
==============================
1st implode call: Array

Warning: Bad arguments to implode() in /usr/local/apache/htdocs/Widget/test.php on line 12
2nd implode call: 
size at end 1
==============================

However uncommenting the first 'echo sizeof()' line gives the following result;
==============================
size at start 3
1st implode call: Array
2nd implode call: first_item+second_Item+third_item
size at end 3
==============================

something not being initialised in implode() ?


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [1999-07-30 17:38 UTC] andrey at cvs dot php dot net
Since implode converts each part of the input array to string, your inside array becomes a string after the first call to implode, and the second call complains about bad arguments.  Implode is working as designed, modify your code.

 [1999-07-30 18:04 UTC] zeev at cvs dot php dot net
implode() is not supposed to change its argument by design.
This is indeed a PHP 4.0 incompatibility that has to be sorted
out.
 [1999-07-30 18:35 UTC] zeev at cvs dot php dot net
Ok, it should be fixed now
 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Tue Jun 30 10:00:01 2026 UTC