Permalink
Browse files

Fixed bug #62073 (Different ways of iterating over an SplMaxHeap resu…

…lt in different keys)
  • Loading branch information...
1 parent c973fef commit 9205c4fd62a769b7db3d00eccdf2ea35b20dd87f @reeze committed May 23, 2012
Showing with 237 additions and 213 deletions.
  1. +1 −1 ext/spl/spl_heap.c
  2. +24 −0 ext/spl/tests/bug62073.phpt
  3. +100 −100 ext/spl/tests/heap_005.phpt
  4. +100 −100 ext/spl/tests/heap_006.phpt
  5. +12 −12 ext/spl/tests/pqueue_001.phpt
View
@@ -950,7 +950,7 @@ static int spl_heap_it_get_current_key(zend_object_iterator *iter, char **str_ke
{
spl_heap_it *iterator = (spl_heap_it *)iter;
- *int_key = (ulong) iterator->object->heap->count;
+ *int_key = (ulong) iterator->object->heap->count - 1;
return HASH_KEY_IS_LONG;
}
/* }}} */
@@ -0,0 +1,24 @@
+--TEST--
+Bug #62073 (different ways of iterating over an SplMaxHeap result in different keys)
+--FILE--
+<?php
+$heap = new SplMaxHeap;
+$heap->insert(42);
+foreach ($heap as $key => $value) {
+ break;
@laruence
laruence May 23, 2012

why do not var_dump the key in the foreach loop body? it's not a good usage, although I think it's no different, and maybe there is no need add one extra test file for this trivial change , since you have changed the other test scripts, which will also reflect this fix.

thanks

+}
+var_dump($key);
+var_dump($value);
+
+$heap = new SplMaxHeap;
+$heap->insert(42);
+var_dump($heap->key());
+var_dump($heap->current());
+?>
+==DONE==
+--EXPECT--
+int(0)
+int(42)
+int(0)
+int(42)
+==DONE==
@@ -18,104 +18,104 @@ foreach ($h as $k => $o) {
===DONE===
<?php exit(0); ?>
--EXPECTF--
-100 => 1
-99 => 2
-98 => 3
-97 => 4
-96 => 5
-95 => 6
-94 => 7
-93 => 8
-92 => 9
-91 => 10
-90 => 11
-89 => 12
-88 => 13
-87 => 14
-86 => 15
-85 => 16
-84 => 17
-83 => 18
-82 => 19
-81 => 20
-80 => 21
-79 => 22
-78 => 23
-77 => 24
-76 => 25
-75 => 26
-74 => 27
-73 => 28
-72 => 29
-71 => 30
-70 => 31
-69 => 32
-68 => 33
-67 => 34
-66 => 35
-65 => 36
-64 => 37
-63 => 38
-62 => 39
-61 => 40
-60 => 41
-59 => 42
-58 => 43
-57 => 44
-56 => 45
-55 => 46
-54 => 47
-53 => 48
-52 => 49
-51 => 50
-50 => 51
-49 => 52
-48 => 53
-47 => 54
-46 => 55
-45 => 56
-44 => 57
-43 => 58
-42 => 59
-41 => 60
-40 => 61
-39 => 62
-38 => 63
-37 => 64
-36 => 65
-35 => 66
-34 => 67
-33 => 68
-32 => 69
-31 => 70
-30 => 71
-29 => 72
-28 => 73
-27 => 74
-26 => 75
-25 => 76
-24 => 77
-23 => 78
-22 => 79
-21 => 80
-20 => 81
-19 => 82
-18 => 83
-17 => 84
-16 => 85
-15 => 86
-14 => 87
-13 => 88
-12 => 89
-11 => 90
-10 => 91
-9 => 92
-8 => 93
-7 => 94
-6 => 95
-5 => 96
-4 => 97
-3 => 98
-2 => 99
-1 => 100
+99 => 1
+98 => 2
+97 => 3
+96 => 4
+95 => 5
+94 => 6
+93 => 7
+92 => 8
+91 => 9
+90 => 10
+89 => 11
+88 => 12
+87 => 13
+86 => 14
+85 => 15
+84 => 16
+83 => 17
+82 => 18
+81 => 19
+80 => 20
+79 => 21
+78 => 22
+77 => 23
+76 => 24
+75 => 25
+74 => 26
+73 => 27
+72 => 28
+71 => 29
+70 => 30
+69 => 31
+68 => 32
+67 => 33
+66 => 34
+65 => 35
+64 => 36
+63 => 37
+62 => 38
+61 => 39
+60 => 40
+59 => 41
+58 => 42
+57 => 43
+56 => 44
+55 => 45
+54 => 46
+53 => 47
+52 => 48
+51 => 49
+50 => 50
+49 => 51
+48 => 52
+47 => 53
+46 => 54
+45 => 55
+44 => 56
+43 => 57
+42 => 58
+41 => 59
+40 => 60
+39 => 61
+38 => 62
+37 => 63
+36 => 64
+35 => 65
+34 => 66
+33 => 67
+32 => 68
+31 => 69
+30 => 70
+29 => 71
+28 => 72
+27 => 73
+26 => 74
+25 => 75
+24 => 76
+23 => 77
+22 => 78
+21 => 79
+20 => 80
+19 => 81
+18 => 82
+17 => 83
+16 => 84
+15 => 85
+14 => 86
+13 => 87
+12 => 88
+11 => 89
+10 => 90
+9 => 91
+8 => 92
+7 => 93
+6 => 94
+5 => 95
+4 => 96
+3 => 97
+2 => 98
+1 => 99
+0 => 100
===DONE===
Oops, something went wrong.

0 comments on commit 9205c4f

Please sign in to comment.