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
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.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: janwalther86 at gmail dot com
New email:
PHP Version: OS:

 

 [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: Fri Mar 29 10:01:28 2024 UTC