PHP :: Request #76024 :: Elements disappear After Interaction with SplHeap
php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #76024 Elements disappear After Interaction with SplHeap
Submitted: 2018-02-28 00:14 UTC Modified: 2018-02-28 15:00 UTC
Votes:2
Avg. Score:3.0 ± 2.0
Reproduced:2 of 2 (100.0%)
Same Version:2 (100.0%)
Same OS:2 (100.0%)
From: mt at mfmello dot com Assigned:
Status: Open Package: SPL related
PHP Version: 7.0.27 OS: Linux Mint 18.1 64bits
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: mt at mfmello dot com
New email:
PHP Version: OS:

 

 [2018-02-28 00:14 UTC] mt at mfmello dot com
Description:
------------
---
From manual page: http://www.php.net/class.splheap
---

After filling a SplHeap object using "SplHeap::insert" and creating an interaction with the object the inserted elements simply disappear, I looked in several forums and I saw many people with the same problem because they did not expect that after looping their elements no longer exist in the initial object.

Original (pt-br):
Após preencher um objeto SplHeap usando "SplHeap::insert" e criar uma interação com o objeto os elementos inseridos simplesmente somem, pesquisei em diversos forúns e vi muitas pessoas com o mesmo problema, pois elas não esperam que após fazer um loop os seus elementos não existam mais no objecto inicial.

Test script:
---------------
<?php

$spl = new SplMinHeap();

$spl->insert(10);
$spl->insert(7);
$spl->insert(5);
$spl->insert(2);

echo 'Size object: ' . $spl->count(); // result 4

echo PHP_EOL;

foreach ($spl as $number)
   echo 'Number: ' . $number . PHP_EOL;

echo 'New size object: ' . $spl->count(); // result 0



Expected result:
----------------
I believe that I and many others hope that after a loop the elements are still inside the object. Because we do not configure the removal of it and we do not execute anything like "SplHeap::extract"


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-02-28 00:41 UTC] carusogabriel34 at gmail dot com
Confirmed: https://3v4l.org/pHeW0
 [2018-02-28 10:18 UTC] cmb@php.net
-Type: Bug +Type: Documentation Problem -Package: SPL_Types +Package: SPL related
 [2018-02-28 12:27 UTC] cmb@php.net
-Summary: Elements Appear After Interaction with SplHeap +Summary: Elements disappear After Interaction with SplHeap
 [2018-02-28 12:50 UTC] salathe@php.net
SplHeap::next() already documents that calling this method (which happens implicitly using foreach) will delete the top node of the heap.
-- http://php.net/manual/en/splheap.next.php
 [2018-02-28 13:51 UTC] mt at mfmello dot com
It is actually provided in the documentation, but is it really by default that it should delete the top object? Using the SplHeap::next method does not deduce that the object will be removed, but rather that the array will simply be advanced one position forward. Even if this action were expected for the programmers it would be very useful to be able to configure this as it does in the SplDoublyLinkedList that we can change the mode of the Interator.

Original (pt-br):
Realmente está previsto na documentação, mas será que realmente por padrão ele deveria deletar o objeto do topo? Utilizando o método SplHeap::next não se deduz que o objeto será removido, mas sim que a matriz simplesmente será avançada uma posição a frente. Mesmo que essa ação fosse esperada para os programadores seria muito útil poder configurar isso assim como ocorre no SplDoublyLinkedList que podemos alterar o modo do interador.
 [2018-02-28 14:44 UTC] salathe@php.net
-Status: Open +Status: Feedback
 [2018-02-28 14:44 UTC] salathe@php.net
Do you want this ticket changed to a feature request, to provide that functionality?
 [2018-02-28 15:00 UTC] mt at mfmello dot com
-Status: Feedback +Status: Open -Type: Documentation Problem +Type: Feature/Change Request
 [2018-02-28 15:00 UTC] mt at mfmello dot com
Yes, I made the change.
This issue could be extended to any looping interaction in the spline data structures that come by default by removing the current element after advancing to the next key in the array. So the community would have more control over their data.

Original (pt-br):
Sim, fiz a alteração.
Essa questão poderia ser estendida para toda interação em loop nas estruturas de dados da biblioteca Spl que venham por padrão removendo o elemento atual após avançar para a próxima chave da matriz. Assim a comunidade teria mais poder de controle sobre seus dados.
 
PHP Copyright © 2001-2018 The PHP Group
All rights reserved.
Last updated: Fri Aug 17 06:01:24 2018 UTC