Bug #17869 Updated: Array sort order broken with more than 256 entries in an associative array?

From: Date: Thu, 20 Jun 2002 09:14:43 +0000
Subject: Bug #17869 Updated: Array sort order broken with more than 256 entries in an associative array?
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-11529@lists.php.net to get a copy of this message
ID: 17869 Updated by: jan@php.net Reported By: adamek@webtrio.de -Status: Open +Status: Feedback Bug Type: Arrays related Operating System: Linux 2.4.16 PHP Version: 4.2.1 New Comment: 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. Previous Comments: ------------------------------------------------------------------------ [2002-06-20 05:07:30] adamek@webtrio.de The bug still stays when replacing some lines: Replace the line $userlist[$q->UID."-".$q->Server] = $q->Username." (".$q->Server.")"; by the lines: $arraykey = $q->UID.".".$q->Server; $arrayvalue = $q->Username." (".$q->Server.")"; $userlist[$arraykey] = $arrayvalue; (key and value prepared) ------------------------------------------------------------------------ [2002-06-20 04:55:00] adamek@webtrio.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 04:50:02] adamek@webtrio.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: [$q->UID.":".$q->Server] and [$q->UID.".".$q->Server] 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. ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=17869&edit=1

« previous php.bugs (#11529) next »