Skip to content

internal iterator rewind handler is called twice #12060

Closed
@ju1ius

Description

@ju1ius

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions