Bug #77903 [NEW]: ArrayIterator stops iterating after offsetSet call
| From: | gituser at yandex dot com | Date: | Mon, 15 Apr 2019 18:52:30 +0000 |
| Subject: | Bug #77903 [NEW]: ArrayIterator stops iterating after offsetSet call | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-220470@lists.php.net to get a copy of this message | ||
From: gituser at yandex dot com
Operating system: ubuntu 18.10
PHP version: 7.3.4
Package: *Programming Data Structures
Bug Type: Bug
Bug description:ArrayIterator stops iterating after offsetSet call
Description:
------------
i use fresh xampp for linux.
it looks like it works fine on earlier php versions e.g. 7.2. i.e. this
is a regression.
i've tested on integer indices only. maybe on other data types the
behavior differs, idk
sorry that i've posted a longer-than-20-lines test script, but when
dealing with iterators, the *sequence* of method calls is important,
that's why so much lines needed. i've done my best to keep the sample
concise but it's still 30 lines long, sorry :(
another (longer) test sample: https://3v4l.org/Ft0Dh
Test script:
---------------
<?php
$a = new ArrayIterator();
$a->rewind();
var_dump($a->valid()); // false
var_dump($a->current()); // null
$a->offsetSet(1,1);
var_dump($a->valid()); // true
var_dump($a->current()); // 1
$a->next();
var_dump($a->valid()); // false
var_dump($a->current()); // null
$a->offsetSet(4,4);
var_dump($a->valid()); // true
var_dump($a->current()); // should: 4; got: undefined value of 'unknown'
data type
$a->next();
var_dump($a->valid()); // should: false; got: true
var_dump($a->current()); // should: null; got: 4
$a->next();
var_dump($a->valid()); // false
var_dump($a->current()); // null
$a->offsetSet(2,2);
var_dump($a->valid()); // should: true; got: false
var_dump($a->current()); // should: 2; got: null
$a->next();
var_dump($a->valid()); // false
var_dump($a->current()); // null
$a->next();
var_dump($a->valid()); // false
var_dump($a->current()); // null
// it'll never return the "2"
Expected result:
----------------
has to be:
$i->valid() === false
$i->current() === null
$i->offsetSet(4,4)
$i->valid() === true
$i->current() === 4
see comments in test sample code for details
Actual result:
--------------
actually is: (the last line)
$i->current() === undefined value of unknown data type
--
Edit bug report at https://bugs.php.net/bug.php?id=77903&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=77903&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=77903&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=77903&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=77903&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=77903&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=77903&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=77903&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=77903&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=77903&r=support
Expected behavior: https://bugs.php.net/fix.php?id=77903&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=77903&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=77903&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=77903&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=77903&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=77903&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=77903&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=77903&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=77903&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=77903&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=77903&r=mysqlcfg