php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #55185 SplMaxHeap only once loopable
Submitted: 2011-07-12 04:19 UTC Modified: 2011-07-12 04:28 UTC
From: janwalther86 at gmail dot com Assigned:
Status: Not a bug Package: SPL related
PHP Version: 5.3.6 OS:
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
14 + 2 = ?
Subscribe to this entry?

 
 [2011-07-12 04:19 UTC] janwalther86 at gmail dot com
Description:
------------
I tried to loop through a SplMaxHeap object multiple times but it only loops once. As there is no option to reset or rewind the heap object I don't see a way to loop through it multiple times.

I noticed that $heap->count() decreases with every loop cycle, perhaps that is the reason.

Test script:
---------------
$heap = new SplMaxHeap();
$heap->insert(1);
$heap->insert(2);
foreach($heap as $number){
  echo $number."\n";
}
foreach($heap as $number){
  echo $number."\n";
}



Expected result:
----------------
2
1
2
1


Actual result:
--------------
2
1


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-07-12 04:28 UTC] scottmac@php.net
-Status: Open +Status: Bogus
 [2011-07-12 04:28 UTC] scottmac@php.net
As it iterates over a heap it extracts the number from it.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Apr 29 15:01:31 2024 UTC