Bug #79726 [NEW]: SplStack::pop breaks stack validity

From: Date: Tue, 23 Jun 2020 14:25:49 +0000
Subject: Bug #79726 [NEW]: SplStack::pop breaks stack validity
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-227609@lists.php.net to get a copy of this message
From:             millet dot gael at gmail dot com
Operating system: OSX
PHP version:      7.4.7
Package:          SPL related
Bug Type:         Bug
Bug description:SplStack::pop breaks stack validity

Description:
------------
Breaking change on SplStack iterator.
If we pop from the stack, the stack become invalid for the last
iteration.
This code was working with php 7.2.x, but is broken with 7.3.x and
7.4.x

Can be fixed by adding "$stack->rewind();" after "$stack->next();"

Test script:
---------------
<?php
$stack = new \SplStack();
$stack->push(1);
$stack->push(2);
$stack->rewind();
while ($stack->valid()) {
    $value = $stack->pop();
    var_dump($value);
    $stack->next();
}

Expected result:
----------------
int(2)
int(1)

Actual result:
--------------
int(2)

-- 
Edit bug report at https://bugs.php.net/bug.php?id=79726&edit=1
-- 
Fix committed:                    https://bugs.php.net/fix.php?id=79726&r=fixed
Fixed in release:                 https://bugs.php.net/fix.php?id=79726&r=alreadyfixed
Need backtrace:                   https://bugs.php.net/fix.php?id=79726&r=needtrace
Need Reproduce Script:            https://bugs.php.net/fix.php?id=79726&r=needscript
Try newer version:                https://bugs.php.net/fix.php?id=79726&r=oldversion
Not developer issue:              https://bugs.php.net/fix.php?id=79726&r=support
Expected behavior:                https://bugs.php.net/fix.php?id=79726&r=notwrong
Not enough info:                  https://bugs.php.net/fix.php?id=79726&r=notenoughinfo
Submitted twice:                  https://bugs.php.net/fix.php?id=79726&r=submittedtwice
register_globals:                 https://bugs.php.net/fix.php?id=79726&r=globals
PHP version support discontinued: https://bugs.php.net/fix.php?id=79726&r=phptooold
Daylight Savings:                 https://bugs.php.net/fix.php?id=79726&r=dst
IIS Stability:                    https://bugs.php.net/fix.php?id=79726&r=isapi
Install GNU Sed:                  https://bugs.php.net/fix.php?id=79726&r=gnused
Floating point limitations:       https://bugs.php.net/fix.php?id=79726&r=float
No Zend Extensions:               https://bugs.php.net/fix.php?id=79726&r=nozend
MySQL Configuration Error:        https://bugs.php.net/fix.php?id=79726&r=mysqlcfg


Thread (6 messages)

« previous php.bugs (#227609) next »