Bug #77903 [Csd]: ArrayIterator stops iterating after offsetSet call

From: Date: Tue, 16 Apr 2019 13:05:07 +0000
Subject: Bug #77903 [Csd]: ArrayIterator stops iterating after offsetSet call
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-220477@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=77903&edit=1 ID: 77903 User updated by: gituser at yandex dot com Reported by: gituser at yandex dot com Summary: ArrayIterator stops iterating after offsetSet call Status: Closed Type: Bug Package: SPL related Operating System: Ubuntu 18.10 (64-bit) PHP Version: 7.3.4 Assigned To: nikic Block user comment: N Private report: N New Comment: nikic@php.net i'm sure such a regression could be easily detected by a unit test. how did it happen that it did get to the production code? don't you think there's a need to unit test this class? if so, where should i post the request to php devs so that they'd create them? (or do they have some other priorities and won't do this anyway?) p.s. idk if you see my comment (the bug is closed after all). if you don't want to answer - at least say that you've seen it please so that i don't have to repeat it to you email directly Previous Comments: ------------------------------------------------------------------------ [2019-04-16 08:41:33] nikic@php.net Fixed in https://github.com/php/php-src/commit/e1b4cabbd6d5ce72bb73ec4988b91c1e62c71335 and https://github.com/php/php-src/commit/9a9eed472b05292f8e8aa82129ea5d1da4b0e0c2. ------------------------------------------------------------------------ [2019-04-16 05:41:38] gituser at yandex dot com Hmm... Looks like SPL_Types https://www.php.net/manual/en/book.spl-types.php which hasn't been updated for more than 5 years, isn't the same as SPL https://www.php.net/manual/en/book.spl.php I think I found the correct category now. ------------------------------------------------------------------------ [2019-04-16 05:25:47] gituser at yandex dot com Package -> SPL_Types ------------------------------------------------------------------------ [2019-04-15 18:52:30] gituser at yandex dot com 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 this bug report at https://bugs.php.net/bug.php?id=77903&edit=1

« previous php.bugs (#220477) next »