Skip to content

Fix GH-8562: SplFileObject::current() returns wrong value after next()#23

Closed
iliaal wants to merge 1 commit intomasterfrom
fix/gh-8562-splfileobject-next-current
Closed

Fix GH-8562: SplFileObject::current() returns wrong value after next()#23
iliaal wants to merge 1 commit intomasterfrom
fix/gh-8562-splfileobject-next-current

Conversation

@iliaal
Copy link
Copy Markdown
Owner

@iliaal iliaal commented Apr 8, 2026

SplFileObject::next() without READ_AHEAD cleared the cached line and incremented current_line_num but didn't advance the stream. When called without a preceding current() (e.g. rewind() then next()), the stream position stayed put, so the subsequent current() read stale data.

The fix reads a line to advance the stream when next() is called with no cached line.

Fixes php#8562

…xt()

SplFileObject::next() without READ_AHEAD cleared the cached line and
incremented current_line_num but didn't advance the stream. When called
without a preceding current() (e.g. rewind() then next()), the stream
position stayed put, so the subsequent current() read stale data.

Read a line to advance the stream when next() is called with no cached
line.

Closes phpGH-8562
@iliaal
Copy link
Copy Markdown
Owner Author

iliaal commented Apr 8, 2026

Submitted upstream as php#21679

@iliaal iliaal closed this Apr 8, 2026
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.

SplFileObject: current() returns wrong result after call to next()

1 participant