|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #53588 SplMinHeap bad insert sort
Submitted: 2010-12-21 14:50 UTC Modified: 2010-12-21 20:53 UTC
From: ojousset49 at yahoo dot fr Assigned: cataphract (profile)
Status: Not a bug Package: SPL related
PHP Version: 5.3.4 OS: RHEL 55 64bits
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: ojousset49 at yahoo dot fr
New email:
PHP Version: OS:


 [2010-12-21 14:50 UTC] ojousset49 at yahoo dot fr
SplMinHeap have the same behavior than SplMaxHeap when inserting data.
Top value of a SplMinHeap object is the max value instead of the min

Test script:
class MySimpleHeap extends SplMinHeap{
    public function  compare( $value1, $value2 ){
        return ( $value1 - $value2 );

$obj = new MySimpleHeap();
$obj->insert( 8 );
$obj->insert( 0 );
$obj->insert( 4 );

foreach( $obj as $number ) {
    echo $number."\n";

// Output display : 8, 4, 0 instead of 0, 4, 8


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2010-12-21 17:01 UTC]
-Assigned To: +Assigned To: cataphract
 [2010-12-21 18:29 UTC]
Automatic comment from SVN on behalf of cataphract
Log: - Fixed bug #53588 (SplMinHeap bad sorting with custom compare
 [2010-12-21 18:29 UTC]
-Status: Assigned +Status: Closed -Type: Feature/Change Request +Type: Bug
 [2010-12-21 18:29 UTC]
This bug has been fixed in SVN.

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.

 [2010-12-21 20:53 UTC]
-Status: Closed +Status: Bogus
 [2010-12-21 20:53 UTC]
Reverted change and closing as bogus.

Turns out the semantics of SplMinHeap::compare() and SplMaxHeap::compare() are different. See:
PHP Copyright © 2001-2018 The PHP Group
All rights reserved.
Last updated: Sun Oct 21 07:01:24 2018 UTC