Re: Bug #764 Updated: ksort mixes the implicit variable types and result is unexpected.

From: Date: Mon, 21 Sep 1998 20:10:29 +0000
Subject: Re: Bug #764 Updated: ksort mixes the implicit variable types and result is unexpected.
References: 1  Groups: php.dev 
Request: Send a blank email to php-dev+get-1337@lists.php.net to get a copy of this message
I just resubmitted my form which closed the bug again accidentally, but I meant to do that anyway. There's no point at keeping that open, since this behavior isn't going to change. Getting around the problem is extremely easy, you can simply prefix all of the indices with something that'll tell PHP they're not numbers, like a leading zero, or some character. Zeev On 21 Sep 1998, Bug Database wrote: > ID: 764 > User Update by: libs@cybercable.tm.fr > Old-Status: Closed > Status: Open > Old-Bug Type: Misbehaving function > Bug Type: Feature/Change Request > Description: ksort mixes the implicit variable types and result is unexpected. > > <? > $toto["001"]="a"; > $toto["010"]="c"; > $toto[(string)"100"]="d"; > $toto["002"]="b"; > $toto["110"]="e"; > > ksort($toto); > for(reset($toto); $test = key($toto); next($toto)) { > echo ($test." (".gettype($test).") : > ".$toto[$test]."<BR>\n"); > }; > ?> > > gives > 100 (integer) : d<BR> > 110 (integer) : e<BR> > 001 (string) : a<BR> > 002 (string) : b<BR> > 010 (string) : c<BR> > > instead of : > 001 (whatever) : a<BR> > 002 (whatever) : b<BR> > 010 (whatever) : c<BR> > 100 (whatever) : d<BR> > 110 (whatever) : e<BR> > > It is agreed that it is not a bug, but the intended functionality is still > not available. > > To make it available at some later time, I would suggest putting either > kasort() or kusort() in some TODO list. > By kasort() I mean a variation of ksort() which only considers the > string value in the sorting comparisons. It wouldn't have to change the > types of keys inside the array, just sort them in another way. > By kusort() I mean to do something like: > function cmp($a,$b) { > if($a==$b) return 0; > return ((string)$a>(string)$b) ? 1:-1; > } > kusort($toto, cmp): > > > [config irrelevant] > > Full Bug description available at: > http://ca.php.net/bugs.php3?id=764 > > > -- > PHP Development Mailing List http://www.php.net/ > To unsubscribe send an empty message to php-dev-unsubscribe@lists.php.net > For help: php-dev-help@lists.php.net > > -- ----------------------------------------------------- Zeev Suraski <zeev@php.net> For a PGP public key, finger bourbon@netvision.net.il -- PHP Development Mailing List http://www.php.net/ To unsubscribe send an empty message to php-dev-unsubscribe@lists.php.net For help: php-dev-help@lists.php.net

« previous php.dev (#1337) next »