Skip to content

Iterator::rewind: link to reset() function vs rewind() function - #5764

Open
terrafrost wants to merge 1 commit into
php:masterfrom
terrafrost:fix-iterator-rewind
Open

Iterator::rewind: link to reset() function vs rewind() function#5764
terrafrost wants to merge 1 commit into
php:masterfrom
terrafrost:fix-iterator-rewind

Conversation

@terrafrost

Copy link
Copy Markdown

No description provided.

@lacatoire lacatoire left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change replaces rewind with reset, but these are different things: reset() is a built-in function that rewinds plain arrays, while Iterator::rewind() is the method foreach actually calls on objects implementing Iterator.

You can follow the call chain in the engine: foreach triggers zend_fe_reset_iterator(), which calls iter->funcs->rewind(iter), wired to zend_user_it_rewind() — which dispatches to the PHP-level rewind method (resolved by name here, called here).

So the original wording was correct. Happy to be wrong if I'm missing something!

@terrafrost

terrafrost commented Aug 18, 2026

Copy link
Copy Markdown
Author

Well then maybe As &foreach; always calls <methodname>rewind</methodname> before starting should be replaced with As &foreach; always calls rewind before starting because, as is, at https://www.php.net/manual/en/iterator.rewind.php, in the Note box, where it says, "As foreach always calls rewind() before starting iteration, manually advancing the iterator position" it links to the function that "rewind[s] the position of a file pointer".

For that matter, maybe it could even say As &foreach; always calls this method before starting.

But, as is, it's hyperlinking to a function that affects file pointers.

</para>
<simpara>
As &foreach; always calls <methodname>rewind</methodname> before starting
As &foreach; always calls <methodname>reset</methodname> before starting

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
As &foreach; always calls <methodname>reset</methodname> before starting
As &foreach; always calls <methodname>Iterator::rewind</methodname> before starting

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're proposing the page link to itself? Is there precedent for that on php.net? In general I think that that's kinda silly. Like making every instance of "World War "2 on the "World War 2" wikipedia article link to itself... I'm not sure that's a very useful change.

I feel like As &foreach; always calls this method before starting would be better.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@terrafrost I agree with your suggestion. Using this method makes more sense.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants