|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #17869 Array sort order broken with more than 256 entries in an associative array?
Submitted: 2002-06-20 04:50 UTC Modified: 2002-06-20 05:29 UTC
From: adamek at webtrio dot de Assigned:
Status: Not a bug Package: Arrays related
PHP Version: 4.2.1 OS: Linux 2.4.16
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 this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: adamek at webtrio dot de
New email:
PHP Version: OS:


 [2002-06-20 04:50 UTC] adamek at webtrio dot de
To reproduce the problem do the following:

1) Read a mysql database table with user names and a double index (UID, server - both numeric) having about 280 entries:

SELECT UID,Server,Username FROM Users ORDER BY UID,Server

2) Preparing the array: $userlist = array();

3) Filling the array:

$result = mysql_query("SELECT UID,Server,Username FROM Users ORDER BY UID,Server");

if ($result)
   while ($q = get_object($result))
       $userlist[$q->UID."-".$q->Server] = $q->Username." (".$q->Server.")";
       // Debug output just to see that filling happens in the right alphabetical order of user names
       echo $userlist[$q->UID."-".$q->Server]."\n";

4) Reading the array:

foreach ($userlist as $key => $value)
   echo $key." = ".$value."\n";

you suddenly notice that the array entry no. 256 and 257 appear at the wrong place (at position count($userlist)-256) - the internal sort order of the array has changed!

I also tried this with array index names in the form:




Both with the same wrong result ... arrays read out don't have the same order as they were filled any more if more than 256 entries are present.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2002-06-20 04:55 UTC] adamek at webtrio dot de
Mistype in my bug report ;-)

The line

while ($q = get_object($result))

must be

while ($q = mysql_fetch_object($result))

of course ..... forgot to replace my mysql query wrapper code with real mysql_ function ....

Of course bug is still present - has nothing to do with mysql ...
 [2002-06-20 05:07 UTC] adamek at webtrio dot de
The bug still stays when replacing some lines:

Replace the line

$userlist[$q->UID."-".$q->Server] = $q->Username."

by the lines:
$arraykey = $q->UID.".".$q->Server;
$arrayvalue = $q->Username." (".$q->Server.")";

$userlist[$arraykey] = $arrayvalue;

(key and value prepared)
 [2002-06-20 05:14 UTC]
can please submit a small script along with some test data (please just link to a page you set up, don't include the test data in the bugreport.

Thank you for your interest in PHP.
 [2002-06-20 05:18 UTC] adamek at webtrio dot de
Sorry Jan, it was a bug in the database structure .... key with the UID value existed twice ..... bug closed
 [2002-06-20 05:29 UTC]
if it was not a bug the report is "bogus". Thank you.
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Sat Oct 23 08:03:33 2021 UTC