php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #18050 asort not sorting properly
Submitted: 2002-06-28 14:28 UTC Modified: 2002-08-20 19:34 UTC
From: bstoppel at ku dot edu Assigned:
Status: Closed Package: Arrays related
PHP Version: 4.2.1 OS: Digital UNIX V4.0F (Rev. 1229)
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: bstoppel at ku dot edu
New email:
PHP Version: OS:

 

 [2002-06-28 14:28 UTC] bstoppel at ku dot edu
I used the example given in the asort documentation. The result is not correct. Here is the example for your convenience:

$fruits = array ("d"=>"lemon", "a"=>"orange", "b"=>"banana", "c"=>"apple");
asort ($fruits);
reset ($fruits);
while (list ($key, $val) = each ($fruits)) {
    echo "$key = $val\n";
}

The actual output is 
d = lemon
a = orange
b = banana
c = apple

The expected output is
c = apple
b = banana
d = lemon
a = orange



Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-06-28 14:37 UTC] rasmus@php.net
Hrm..  On my Linux box your script outputs:

c = apple
b = banana
d = lemon
a = orange

Are you on a 64-bit platform?  I'm looking at the zend_qsort() function but I don't see an obvious mistake.
 [2002-06-28 15:05 UTC] bstoppel at ku dot edu
The platform that I am using is 64-bit.

BTW - before upgrading to 4.21, we were using 4.06 and the sort function worked fine.
 [2002-06-28 15:15 UTC] mfischer@php.net
Sterling mentioned something about a cast fix in zend_qsort, please try http://snaps.php.net/php4-latest.tar.gz
 [2002-08-20 16:52 UTC] long at ku dot edu
I'm the person responsible for PHP on bstoppel's system.  I've just built php4-200208201200 and it looks like asort() is working properly again.  However, I'm seeing this message when running php:

Unaligned access pid=26595 <php> va=0x1400b701c pc=0x12025d930 ra=0x12025d040 inst=0xb4010000

which indicates an unaligned memory access.  I couldn't build zend_API.c without adding an #include "php.h" to get the macro re-definition of snprintf() but I was told that could be a "bad" thing to do so perhaps that is causing the unaligned memory accesses...
 [2002-08-20 19:34 UTC] nohn@php.net
Duplicate to bug #17449. This bug is already closed in current CVS. 4.3.0 will work, I hope 4.2.3 will work too.
 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Wed Oct 07 11:00:02 2026 UTC