ID: 27142 User updated by: tomas dot matousek at matfyz dot cz Reported By: tomas dot matousek at matfyz dot cz Status: Open Bug Type: Zend Engine 2 problem Operating System: WinXP PHP Version: 5.0.0b3 (beta3) New Comment:
I realize differences between loosly typed languages and the others. Nevertheless, note that e.g. JavaScript is also loosely typed yet standard behavior of comparison operators. IMHO better solution suitable for PHP is to compare numeric values of string at first. If equals than perform string comparison. This ordering is linear so no problems will occure. Moreover, the behaviour will not be much different from the current one. The only difference I see now: "1zz" > "10a" using current comparison and it will be "1zz" < "10a" using proposed one. Previous Comments: ------------------------------------------------------------------------ [2004-02-05 16:28:46] [EMAIL PROTECTED] Probably you have in mind C, C++ or Java... Any of these languages is not loosely typed. One pays for that PHP is loosely typed language somehow. For example take a look at : http://bugs.php.net/bug.php?id=21728 . I think this (bug #27142) is related to (bug #21728) ------------------------------------------------------------------------ [2004-02-05 14:30:59] tomas dot matousek at matfyz dot cz Well, I can choose another sorting type by the 2nd argument. But that doesn't solve the problem with the less-than (greater-than) operator. This operator is supposed to be transitive in common programming languages. But in PHP it is not: "101a" < "6" ... string comparison "6" < "100" ... numerical comparison "100" < "101a" ... string comparison So I get the result "101a" < "101a" which is nonsense. The non-transitivity obviously cause the problem with sorting which I've reported. Maybe it is intended behavior but there is no mention about it in the documentation. ------------------------------------------------------------------------ [2004-02-04 19:29:56] [EMAIL PROTECTED] See http://www.php.net/asort and notice the 2nd option for this function. Then see http://www.php.net/sort what values it accepts. Then try those values. Then fix your own compare function. ------------------------------------------------------------------------ [2004-02-04 06:54:13] tomas dot matousek at matfyz dot cz Description: ------------ The way in which elements of an array are compared is inconsistent. Reproduce code: --------------- $a = $c = array("101a","100","6"); $b = $d = array("100","6","101a"); // standard comparison: $f = create_function('$a,$b','return ($a<$b) ? -1:($a>$b ? +1:0);'); asort($a); asort($b); uasort($c,$f); uasort($d,$f); print_r($a); print_r($b); print_r($c); print_r($d); Expected result: ---------------- Than I would expect all 'print_r' print arrays with the same order of values. I would expect that items implicitly converted into numbers during comparison should precede those of type string. Actual result: -------------- Array ( [2] => 6 [1] => 100 [0] => 101a ) Array ( [2] => 101a [1] => 6 [0] => 100 ) Array ( [2] => 6 [1] => 100 [0] => 101a ) Array ( [2] => 101a [1] => 6 [0] => 100 ) ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=27142&edit=1