php / php/doc-en

Clarify that Iterator->rewind() must be called before a foreach

Open
#1,300 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug Category: Documentation Category: Engine
Dominant language
XML
Stars
596
Forks
890
Avg merge
1d 15h
Merged PRs (30d)
55

Description

From manual page: https://php.net/iterator.rewind

Many comments in the manual state that foreach calls the rewind method before iterating. But it always seems as if this is something that foreach just does, maybe for safety. But that's a misunderstanding. In a final comment in https://bugs.php.net/bug.php?id=63823, levim says very clearly that calling rewind before using an iterator is mandatory and trying to get values from an unrewound iterator is undefined behaviour. I can't find this clear statement in the manual. At least, it should be found in articles about the current() and next() methods (which could be many). This would have saved me some hours today...

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Iterator::rewind() manual page and review the related current() and next() documentation mentioned in the issue. Clarify that rewind() must be called before reading an iterator and document the consequence of using an unrewound iterator, then verify the wording and documentation links in the PHP manual build.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
documentation
Issue type
Documentation
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.