[php-src] Issue #7979: CachingIterator::hasNext() advances DatePeriod iterator

From: Date: Sat, 22 Jan 2022 16:37:44 +0000
Subject: [php-src] Issue #7979: CachingIterator::hasNext() advances DatePeriod iterator
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-239227@lists.php.net to get a copy of this message
Issue: https://github.com/php/php-src/issues/7979 Comment Author: aragon999 For a short weekend distraction I looked a bit around in the source code which seems to be responsible for this bug. It seems that this bug only occurs with InternalIterators. For example the following code (from a [comment](https://www.php.net/manual/en/cachingiterator.hasnext.php#105934) in the PHP docs) seems to not be affected by this issue: https://3v4l.org/P6icu Since the Caching Iterator checks that the element of the internal iterator (which is one step ahead in the actual iteration) is valid, I then looked into the code which is responsible for the validation in the case of an InternalIterator: https://github.com/php/php-src/blob/024d5f4b63074bb9d4b84f778a7f723a19845d5e/Zend/zend_interfaces.c#L587-L600 In particular the zend_internal_iterator_ensure_rewound function https://github.com/php/php-src/blob/024d5f4b63074bb9d4b84f778a7f723a19845d5e/Zend/zend_interfaces.c#L514-L526 seems to be responsible for the faulty behavior described here. Unfortunately I have no idea how to fix this problem, since I lack understanding how it should be addressed.

« previous php.bugs (#239227) next »