Bug #79203 [NEW]: Inconsistent behaviour of ArrayIterator
| From: | mail at dabla dot ch | Date: | Fri, 31 Jan 2020 13:59:57 +0000 |
| Subject: | Bug #79203 [NEW]: Inconsistent behaviour of ArrayIterator | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-225275@lists.php.net to get a copy of this message | ||
From: mail at dabla dot ch
Operating system: Linux
PHP version: 7.4.2
Package: SPL related
Bug Type: Bug
Bug description:Inconsistent behaviour of ArrayIterator
Description:
------------
When calling offsetUnset for the only element in an ArrayObject and then
append one item, the resulting position of an associated ArrayIterator
doesn't seem to be well defined.
Steps to reproduce:
- Create an ArrayObject with one item.
- Get an ArrayIterator for the ArrayObject.
- Repeat:
- Call offsetUnset with the key of the one element in the array.
Note: Calling offsetUnset on the array or the iterator does not
change the
behaviour.
- Append an item to the ArrayObject.
- check if the iterator is valid
Until php 7.2 the iterator did always point to the appended element.
Test script:
---------------
<?php
$a = new ArrayObject(['item']);
$i = $a->getIterator();
for($c = 0; $c < 100; $c++) {
echo ($i->valid() ? 'valid' : 'invalid') . PHP_EOL;
if($i->valid()) {
$a->offsetUnset($i->key());
}
$a->append('item');
}
Expected result:
----------------
The behaviour should at least be consistent. It would be best to have
the same behaviour as with php7.2, meaning the test script would always
output "valid".
Actual result:
--------------
The behaviour is inconsistent. The test script outputs:
valid
valid
valid
valid
valid
valid
valid
valid
invalid
invalid
invalid
invalid
invalid
invalid
invalid
invalid
valid
invalid
valid
invalid
--
Edit bug report at https://bugs.php.net/bug.php?id=79203&edit=1
--
Fix committed: https://bugs.php.net/fix.php?id=79203&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=79203&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=79203&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=79203&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=79203&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=79203&r=support
Expected behavior: https://bugs.php.net/fix.php?id=79203&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=79203&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=79203&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=79203&r=globals
PHP version support discontinued: https://bugs.php.net/fix.php?id=79203&r=phptooold
Daylight Savings: https://bugs.php.net/fix.php?id=79203&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=79203&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=79203&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=79203&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=79203&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=79203&r=mysqlcfg