Doc #76024 [Opn->Fbk]: Elements disappear After Interaction with SplHeap

From: Date: Wed, 28 Feb 2018 14:44:21 +0000
Subject: Doc #76024 [Opn->Fbk]: Elements disappear After Interaction with SplHeap
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-15483@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=76024&edit=1

 ID:                 76024
 Updated by:         salathe@php.net
 Reported by:        mt at mfmello dot com
 Summary:            Elements disappear After Interaction with SplHeap
-Status:             Open
+Status:             Feedback
 Type:               Documentation Problem
 Package:            SPL related
 Operating System:   Linux Mint 18.1 64bits
 PHP Version:        7.0.27
 Block user comment: N
 Private report:     N

 New Comment:

Do you want this ticket changed to a feature request, to provide that functionality?


Previous Comments:
------------------------------------------------------------------------
[2018-02-28 13:51:07] 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 12:50:51] 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 10:18:30] cmb@php.net

This behavior is by design[1].  Changing to doc bug.

[1]
<https://github.com/php/php-src/blob/PHP-7.2.3/ext/spl/spl_heap.c#L945-L961>
<https://github.com/php/php-src/blob/PHP-7.2.3/ext/spl/spl_heap.c#L885-L889>

------------------------------------------------------------------------
[2018-02-28 00:41:57] carusogabriel34 at gmail dot com

Confirmed: https://3v4l.org/pHeW0

------------------------------------------------------------------------
[2018-02-28 00:14:45] 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"



------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=76024&edit=1


Thread (1 message)

  • salathe@php.net
  • Unknown Message
    • salathe@php.net
« previous php.doc.bugs (#15483) next »