#21444 [Opn->Bgs]: Asort output not fully sorted in mixed type array with BOOLEANs
| From: | andrey@php.net | Date: | Sat, 18 Jan 2003 16:15:11 +0000 |
| Subject: | #21444 [Opn->Bgs]: Asort output not fully sorted in mixed type array with BOOLEANs | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-30473@lists.php.net to get a copy of this message | ||
ID: 21444
Updated by: andrey@php.net
Reported By: xxx1844@thihigh.com
-Status: Open
+Status: Bogus
Bug Type: Arrays related
Operating System: Windows XP Pro Build 2600
PHP Version: 4.3.0
New Comment:
IMO this is not PHP problem but the way the compares are done. You
have to master the type juggling to see that the result is correct. I
have reduced your testcase to this :
<?php
$arr1 =
array("a","b","c","d","4",5,4,"true","TRUE",true);
sort($arr1);
var_dump($arr1);
?>
The output is :
array(10) {
[0]=>
bool(true)
[1]=>
int(4)
[2]=>
string(1) "4"
[3]=>
string(4) "TRUE"
[4]=>
string(1) "a"
[5]=>
string(1) "b"
[6]=>
string(1) "c"
[7]=>
string(1) "d"
[8]=>
string(4) "true"
[9]=>
int(5)
}
It may look strange - why (int)5 is after all the strings. This is
because "4" is lower than (int) 5, "4" is before "true" and
"true" is
before 5. The first 2 are obvious, the third one is not. But it is ok.
It's better not to mix types in the array. If 5 is changed to "5" then
"5" goes right after "4".
Bogusifying
Previous Comments:
------------------------------------------------------------------------
[2003-01-05 16:44:32] xxx1844@thihigh.com
Last addition: I meant sort() where I used asort(), but the result is
the same....
------------------------------------------------------------------------
[2003-01-05 16:32:32] xxx1844@thihigh.com
Well, it appears to be only related to the BOOLEAN array item. Removing
that from the original array leaves a perfectly sorted array as far as
I can see now.
------------------------------------------------------------------------
[2003-01-05 16:26:51] xxx1844@thihigh.com
I use PHP4.0.3 on Apache 1.3.27, both standard binaries as supplied on
the download site. Freshly installed yesterday. No modifications. I
used the php.ini-recommended file as php.ini
Installed exactly as prescribed in install.txt, only instead of c:/php
I use d:/program files/php and changed the ini accordingly.
Adapted the apache conf file as described.
I used below script in an attempt to judge workload forced on the php
server as well as asort() speed. Output is a bit large to add here, but
can be requested via my email. In short, the array IS sorted, but in
all identical "subrows" every now and then one or two array items are
1's (I assume the equivalent of TRUE. Rerunning the script results in
the SAME faults. Sorting within the script twice or more does not
change the faulty array.
Tried with single-type arrays, that doesn't seem to produce the same
errors, but this was not thoroughly tested.
I am sorry, but I haven't figured out a way to get a backtrace yet, I
am relatively new to this PHP stuff.
For your convenience, you can run the script from my server by opening
http://eniac.xs4all.nl/tut8.php and see my PHP server
details on
http://eniac.xs4all.nl/x345info.php (I noticed
this script still 'sees'
remainders of previous 1.3.24 apache as well as the correct 1.3.27
installs, allthough the .24 has been removed...
More info ? Contact me at my email. Thanks!
<?php
$arr1 =
array("a","b","c","d","4",5,4,"true","TRUE",true);
/*
concatenate to itself 10 times to get a real LONG array (5120
elements)
*/
for ($p = 1; $p < 10; $p++)
{ $arr1 = array_merge ($arr1,$arr1); }
asort($arr1);
foreach ($arr1 as $val)
{ print $val." ";}
?>
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=21444&edit=1