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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
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

Pull Requests

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-2025 The PHP Group
All rights reserved.
Last updated: Thu Jul 17 02:01:33 2025 UTC