php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #77903 ArrayIterator stops iterating after offsetSet call
Submitted: 2019-04-15 18:52 UTC Modified: 2019-04-16 13:38 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: gituser at yandex dot com Assigned: nikic (profile)
Status: Closed Package: SPL related
PHP Version: 7.3.4 OS: Ubuntu 18.10 (64-bit)
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: gituser at yandex dot com
New email:
PHP Version: OS:

 

 [2019-04-15 18:52 UTC] 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

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2019-04-16 05:25 UTC] gituser at yandex dot com
-Package: *Programming Data Structures +Package: SPL_Types -Operating System: ubuntu 18.10 +Operating System: Ubuntu 18.10 (64-bit)
 [2019-04-16 05:25 UTC] gituser at yandex dot com
Package -> SPL_Types
 [2019-04-16 05:41 UTC] gituser at yandex dot com
-Package: SPL_Types +Package: SPL related
 [2019-04-16 05:41 UTC] 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 08:07 UTC] nikic@php.net
-Assigned To: +Assigned To: nikic
 [2019-04-16 08:41 UTC] nikic@php.net
-Status: Assigned +Status: Closed
 [2019-04-16 13:05 UTC] gituser at yandex dot com
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
 [2019-04-16 13:14 UTC] nikic@php.net
@gituser: A regression test for this issue has been added when the bug was fixed, see https://github.com/php/php-src/blob/master/ext/spl/tests/bug77903.phpt. PHP does not use unit tests, all tests are integration tests.

As to why this was not spotted by any of the existing tests: None of them were testing the exact sequence of operations necessary to trigger this bug.
 [2019-04-16 13:15 UTC] gituser at yandex dot com
btw, when you post a uri in plain text, make sure that you don't put any non-space char in the immediate vicinity of it. e.g. if you want to put a period directly after this uri, don't forget to add a space between them. the uri specification forbids space chars, thus the uri parser will detect that the period isn't part of the uri. and if you don't, it may decide that the period IS its part (since the uri specification allows that), thus breaking your uri. e.g. the uri you provided https://github.com/php/php-src/commit/9a9eed472b05292f8e8aa82129ea5d1da4b0e0c2. returns the 404 status code. it wouldn't if there was a space: https://github.com/php/php-src/commit/9a9eed472b05292f8e8aa82129ea5d1da4b0e0c2 .
 [2019-04-16 13:19 UTC] gituser at yandex dot com
hmm... it seems that the php bugtracker itself has a bug and doesn't recognize the period if it is in the end of the post (it hasn't though, as the specs allows that). you may report it if you want :) (i won't - i feel too lazy for that :)
 [2019-04-16 13:21 UTC] gituser at yandex dot com
p.s.
* -it hasn't though as- _it doesn't have to though, as_
excuse me my English :)
 [2019-04-16 13:32 UTC] gituser at yandex dot com
ah, now i see. excuse me for asking stupid questions about tests. i had to read all links you provided first, and only then ask questions :)
you're following tdd, right? i didn't expect the bug will be fixed so quickly, thank you for good job!
 [2019-04-16 13:38 UTC] gituser at yandex dot com
-i had to read- _i should have read_
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 13:01:29 2024 UTC