ID: 17307 User updated by: fcartegnie at nordnet dot fr Reported By: fcartegnie at nordnet dot fr -Status: Bogus +Status: Open Bug Type: Arrays related Operating System: Linux -PHP Version: 4.2.1 +PHP Version: 4.4.5 New Comment:
Still broken on 4.4.5... Still using homemade usort routine for 4 years now. The usort functions really needs to be fixed ! Before usort()<br> Value: E<br> Value: C<br> Value: B<br> Value: D<br> Value: A<br> <p>After usort()<br> Value: A<br> Value: D<br> Value: B<br> Value: C<br> Value: E<br> Previous Comments: ------------------------------------------------------------------------ [2002-06-26 08:12:55] david dot derr at milesmedia dot com Hi all. I think this is still a bug as I can partially recreate the behaviour that [EMAIL PROTECTED] 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 ------------------------------------------------------------------------ [2002-06-17 06:52:12] timebreaker at newmail dot 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] [EMAIL PROTECTED] Heh, ok. Still better then a bug in PHP :) thx. ------------------------------------------------------------------------ [2002-06-04 13:44:21] mauf at franzoni dot 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 at franzoni dot 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 :-( ) ------------------------------------------------------------------------ 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