Description
Hi,
The InternalIterator class (in zend_interfaces.c) uses an internal rewind_called flag to ensure that internal iterators are always rewound. This flag is checked by the zend_internal_iterator_ensure_rewound function, in the following methods:
However, in the InternalIterator::rewind() method, the rewind_called flag is not properly set when the iterator has a rewind handler. As a result, the internal iterator's rewind handler is always called twice on first iteration.
This is problematic since internal iterators can perform potentially heavy initialization logic in the rewind handler (like performing a query in the case of a database result-set iterator).
PHP Version
PHP 8.3-dev
Operating System
irrelevant
Description
Hi,
The
InternalIteratorclass (inzend_interfaces.c) uses an internalrewind_calledflag to ensure that internal iterators are always rewound. This flag is checked by thezend_internal_iterator_ensure_rewoundfunction, in the following methods:InternalIterator::current()InternalIterator::key()InternalIterator::next()InternalIterator::valid()However, in the
InternalIterator::rewind()method, therewind_calledflag is not properly set when the iterator has a rewind handler. As a result, the internal iterator's rewind handler is always called twice on first iteration.This is problematic since internal iterators can perform potentially heavy initialization logic in the
rewindhandler (like performing a query in the case of a database result-set iterator).PHP Version
PHP 8.3-dev
Operating System
irrelevant