PHP 4.0 Bug #5019: ksort is broken
| From: | massaro at nextis dot com dot br | Date: | Wed, 14 Jun 2000 00:18:47 +0000 |
| Subject: | PHP 4.0 Bug #5019: ksort is broken | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-21276@lists.php.net to get a copy of this message | ||
From: massaro@nextis.com.br
Operating system: Linux
PHP version: 4.0.0 Release
PHP Bug Type: Misbehaving function
Bug description: ksort is broken
<?php
$ls[1] = 1;
$ls['b'] = 1;
$ls[0] = 1;
$ls['a'] = 1;
ksort($ls);
while (list($k, $v) = each($ls)) {
print "$k -> $v<br>\n";
}
?>
PHP 4 prints
b -> 1
0 -> 1
a -> 1
1 -> 1
But PHP 3 prints
0 -> 1
1 -> 1
a -> 1
b -> 1
which is the correct behaviour.
The problem is with the array item indexed with "0".
A detailed explanation:
For string keys, the keys which are before the 0 in the result remain (ordered) before the 0, and
the keys after the 0 remain (ordered) after the 0 in the result.
The numeric keys are ordered in the end of the list (which is also incorrect because numbers should
come before letters).
All this can be concluded with this example and some variations:
<?php
$ls['c'] = 1;
$ls[1] = 1;
$ls['b'] = 1;
$ls[0] = 1;
$ls['d'] = 1;
$ls[2] = 1;
$ls['a'] = 1;
ksort($ls);
while (list($k, $v) = each($ls)) {
print "$k -> $v<br>\n";
}
?>