Bug #17307 Updated: sorting using usort() does not produce correct result anymore

From: Date: Wed, 26 Jun 2002 12:12:56 +0000
Subject: Bug #17307 Updated: sorting using usort() does not produce correct result anymore
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-12122@lists.php.net to get a copy of this message
ID: 17307 Updated by: david.derr@milesmedia.com Reported By: fcartegnie@nordnet.fr Status: Bogus Bug Type: Arrays related Operating System: Linux PHP Version: 4.2.1 New Comment: Hi all. I think this is still a bug as I can partially recreate the behaviour that fcartegnie@nordnet.fr reported. On a script that uses a function passed to usort that always returns 0 (implying equal values), I am seeing that the order of elements in the array is being modified. The only reason I consider this a bug is because that was not the case in the earlier version I tested. Here are the details: -The code I used on both systems: <? //The function usort will use. Returns 0 implying that every comparison is equal. function fake_sort($left, $right){ return 0; } //create our aTest array and add some data to it $aTest = array(); $aTest[] = "E"; $aTest[] = "C"; $aTest[] = "B"; $aTest[] = "D"; $aTest[] = "A"; //output the order of elements in the array before running usort on it. reset($aTest); echo "Before usort()<br>\n"; while(list($key, $val) = each($aTest)){ echo "Value: ".$val."<br>\n"; } //sort it usort($aTest, "fake_sort"); //output the order of elements in the array after running usort on it. reset($aTest); echo "<p>After usort()<br>\n"; while(list($key, $val) = each($aTest)){ echo "Value: ".$val."<br>\n"; } ?> -Incorrect (unexpected) Results System: RH 7.2, Apache 1.3.26, PHP 4.2.1 Output: Before usort() Value: E Value: C Value: B Value: D Value: A After usort() Value: A Value: D Value: B Value: C Value: E -Correct (expected) Results System: RH 7.2, Apache 1.3.26, PHP 4.1.2 Output: Before usort() Value: E Value: C Value: B Value: D Value: A After usort() Value: E Value: C Value: B Value: D Value: A Previous Comments: ------------------------------------------------------------------------ [2002-06-17 06:52:12] timebreaker@newmail.ru Hi! It's really a problem. I tried to write simple ascending sort routine and got strange results too. Met the conditions at Intel P-133/Win98/Apache2.0.35/PPH4.2.0 and PHP4.2.1, it doesn't matter what the version is. In 4.0.6/4.1.x everything works... ------------------------------------------------------------------------ [2002-06-04 13:58:40] mfischer@php.net Heh, ok. Still better then a bug in PHP :) thx. ------------------------------------------------------------------------ [2002-06-04 13:44:21] mauf@franzoni.info I fixed the problem in my sort routine... it works now (for 4.2.1, so far it seems it was 4.0.6 the buggy one as it has worked for a long while). So far there may be at most a backward compatibility issue (I still have to check back in 4.0.6) but it is no longer worth the critical status for sure... sorry for the bothering, cheers, mauro ------------------------------------------------------------------------ [2002-06-04 12:00:07] mauf@franzoni.info No, I hit the problem on a P3 first... currently testing on a celeron - both using apache 2.0.36, debian with 2.4.18 on p3, rh7.2 (2.4.7-10) on celeron. here is the config, if it can helps: ./configure \ --prefix=/usr/local/php4-200206040600 \ --with-mysql=/usr/local/mysql-3.23.49 \ --with-apxs2=/usr/local/httpd-2.0.36/bin/apxs \ --enable-track-vars \ --enable-sigchild \ --enable-shared \ --enable-cxx \ --enable-cli=yes (I tried to track it a while but I get scrambled when it comes into the zend modules :-( ) ------------------------------------------------------------------------ [2002-06-04 10:35:57] mfischer@php.net Setting to critical without further investigation, hope someone can check this out soon. Btw, are you on a 64bit platform? ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at http://bugs.php.net/17307 -- Edit this bug report at http://bugs.php.net/?id=17307&edit=1

« previous php.bugs (#12122) next »