php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #1629 for x undefined values in an array, implode concatenates the last x + 1 items
Submitted: 1999-06-29 18:20 UTC Modified: 1999-06-30 12:08 UTC
From: codemaster at randombytes dot com Assigned:
Status: Closed Package: Misbehaving function
PHP Version: 3.0.7 OS: Linux x86
Private report: No CVE-ID: None
 [1999-06-29 18:20 UTC] codemaster at randombytes dot com
<table border=3>
<tr><th colspan=6>Original array = ("abc", "def", "ghi", "jkl", "stuck", "together")</th></tr>
<tr bgcolor=ff0000>
<th>0 = undef <th>1 = undef <th>2 = undef <th>3 = undef <th>4 = undef <th>5 = undef
</tr>
<tr bgcolor=ffff88>
<!-- *** PART 1 *** -->
<?php
        $x = array("abc", "def", "ghi", "jkl", "stuck", "together");

        for ($i = 0; $i < count($x); $i++) {
                echo "<td valign=top>";
                $temp = $x[$i];
                $x[$i] = $y;
                echo implode("<br>", $x);
                $x[$i] = $temp;
                echo "</td>";
        }
?>
</tr>
<tr><th colspan=6>Original array = array($y)</th></tr>
<tr bgcolor=ff0000>
<th>1 items <th>2 items <th>3 items <th>4 items <th>5 items <th>6 items
</tr>
<tr bgcolor=ffff88>
<!-- *** PART 2 *** -->
<?php
        $x = array($y);

        for ($i = 1; $i < 7; $i++) {
                echo "<td valign=top>";
                $x[$i] = "item$i";
                echo implode("<br>", $x);
                echo "</td>";
        }
?>
</tr>
<tr><th colspan=6>Original array = array("abc", "def", "ghi", "jkl", "mno", "pqr", "stu", "vwx", "123", "456", "789")</th></tr>
<tr bgcolor=ff0000>
<th>1 undef <th>2 undefs <th>3 undefs <th>4 undefs <th>5 undefs <th>6 undefs
</tr>
<tr bgcolor=ffff88>
<!-- *** PART 3 *** -->
<?php
        $x = array("abc", "def", "ghi", "jkl", "mno", "pqr", "stu", "vwx", "123", "456", "789");

        for ($i = 0; $i < count($x); $i++) {
                echo "<td valign=top>";
                $x[$i] = $y;
                echo implode("<br>", $x);
                echo "</td>";
        }
?>
</tr>
</table>

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [1999-06-29 22:57 UTC] jim at cvs dot php dot net
And the bug is? What is being output versus what you expect to see?
It's hard to make much sense of your example, and the output looks
reasonable to me.
 [1999-06-30 09:01 UTC] codemaster at randombytes dot com
More detail:  If there is one undefined value in an array passed to implode(),
the last two items in the array are concatenated without the delimiter.  If there
are two undef's, the last three are concatenated.  If there are three, the last
four, etc.

After a little more research, this problem seems to apply to the PHP 3.0.7
installation I was using.  I compiled the RedHat 6.0 SRPM and installed it.

RedHat has a PHP 3.0.9 RPM on their update site ftp://ftp.redhat.com.
See http://www.redhat.com/mirrors.html for a list of mirrors.  This newer
version doesn't have this problem.
 [1999-06-30 12:08 UTC] jim at cvs dot php dot net
Silly Red Hat.
 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Tue Jun 30 09:00:02 2026 UTC