]> granicus.if.org Git - php/commitdiff
- Fixed bug #53588 (SplMinHeap bad sorting with custom compare
authorGustavo André dos Santos Lopes <cataphract@php.net>
Tue, 21 Dec 2010 17:29:14 +0000 (17:29 +0000)
committerGustavo André dos Santos Lopes <cataphract@php.net>
Tue, 21 Dec 2010 17:29:14 +0000 (17:29 +0000)
  function).

NEWS
ext/spl/spl_heap.c
ext/spl/tests/bug53588.phpt [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index 849d9ddb80ab6cb1c2b7feec8457735751279aaa..20b20f9956c73b04bf52cd788ace70f2f2862a75 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -70,6 +70,8 @@
 - SPL extension:
   . Fixed bug #53515 (property_exists incorrect on ArrayObject null and 0
     values). (Felipe)
+  . Fixed bug #53588 (SplMinHeap bad sorting with custom compare function).
+    (Gustavo)
     
 - SQLite extension:
   . Fixed memory leaked introduced by the NULL poisoning patch (Mateusz Kocielski, Pierre)
index f72947838813a48f43c995f3c0616930d2d0e9b7..52f2008cdbf9dd953a179dddac22979aec208bf6 100644 (file)
@@ -176,7 +176,7 @@ static int spl_ptr_heap_zval_min_cmp(spl_ptr_heap_element a, spl_ptr_heap_elemen
                spl_heap_object *heap_object = (spl_heap_object*)zend_object_store_get_object((zval *)object TSRMLS_CC);
                if (heap_object->fptr_cmp) {
                        long lval = 0;
-                       if (spl_ptr_heap_cmp_cb_helper((zval *)object, heap_object, (zval *)a, (zval *)b, &lval TSRMLS_CC) == FAILURE) {
+                       if (spl_ptr_heap_cmp_cb_helper((zval *)object, heap_object, (zval *)b, (zval *)a, &lval TSRMLS_CC) == FAILURE) {
                                /* exception or call failure */
                                return 0;
                        }
diff --git a/ext/spl/tests/bug53588.phpt b/ext/spl/tests/bug53588.phpt
new file mode 100644 (file)
index 0000000..1546908
--- /dev/null
@@ -0,0 +1,23 @@
+--TEST--
+Bug #53588 (SplMinHeap bad sorting with custom compare function)
+--FILE--
+<?php
+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";
+}
+--EXPECT--
+0
+4
+8
+