php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #9645 usort, uasort, uksort fail every other time
Submitted: 2001-03-09 01:40 UTC Modified: 2001-04-28 17:17 UTC
From: busterb at mail dot utexas dot edu Assigned:
Status: Closed Package: Arrays related
PHP Version: 4.0.4pl1 OS: FreeBSD 4.0 Release
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: busterb at mail dot utexas dot edu
New email:
PHP Version: OS:

 

 [2001-03-09 01:40 UTC] busterb at mail dot utexas dot edu
usort, uasort and uksort all fail to sort an array 
properly every other time they are called, unless the 
array is reset() after each call.

This is a snippet from a class that fails every other time 
it is called.

    var $sort_field;

    function cmp ($a, $b) {
        return ($a[$this -> sort_field] > $b[$this -> 
sort_field]);
    }
 
    function sort_records ($sort_field) {
        $this -> sort_field = $sort_field;
        uasort ($this -> record_data, array($this, "cmp"));
    }

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-03-29 06:12 UTC] stas@php.net
Could you please provide short self-contained script
demonstrating the problem (including data sample)?
 [2001-04-28 15:38 UTC] derick@php.net
No feedback. If this problem persists with PHP 4.0.5 which
will be released next week, please reopen this report.

Derick
 [2001-04-28 17:17 UTC] busterb at mail dot utexas dot edu
I tried to produce a small, self-contained example of the 
problem with uasort, but I had already moved my code away 
from these routines in favor of an external sort.

Sadly, I couldn't reproduce the problem in a smaller 
context, so it must have just been a bug in my code. If 
anything, the cmp function is probably wrong, since it 
returns 0 for the < case.

 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 09:01:28 2024 UTC