|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #28739 uasort and array_udiff doesn't work together
Submitted: 2004-06-11 08:32 UTC Modified: 2004-07-11 21:23 UTC
Avg. Score:4.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: rodolfo at rodsoft dot org Assigned:
Status: Closed Package: Arrays related
PHP Version: 5.0.0RC2 OS: linux 2.6.6
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.
Block user comment
Status: Assign to:
Bug Type:
From: rodolfo at rodsoft dot org
New email:
PHP Version: OS:


 [2004-06-11 08:32 UTC] rodolfo at rodsoft dot org
If you call uasort with one callback function and then call array_udiff with another callback function, this last call will use first's callback. If we first call array_udiff and then call uasort, everything goes well.

Reproduce code:
class p
   public $x;
   function __construct($x){$this->x=$x;}
function a(&$a, &$b){return $a->x - $b->x;}
function b(&$a, &$b){return $a->y - $b->y;}

$p1 = array(new p(2), new p(1), new p(0));
$p2 = array(new p(0), new p(2), new p(3));

uasort($p1, 'a');
echo "\n";
print_r(array_udiff($p1,$p2, 'b')); 

Expected result:
Notice: Undefined property: p::$y in tst.php on line 8

Actual result:
    [2] => p Object
            [x] => 0

    [1] => p Object
            [x] => 1

    [0] => p Object
            [x] => 2

    [1] => p Object
            [x] => 1



Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2004-06-11 17:06 UTC] rodolfo at rodsoft dot org
This problem apparently is in uasort. If you change uasort for, say, uksort (and make code changes accordingly), the problem disappears.
 [2004-07-11 21:23 UTC]
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
Thank you for the report, and for helping us make PHP better.

The reason : 
array_*diff() and array_*intersect() not clearing the fci cache before work
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Fri Apr 16 15:01:24 2021 UTC