You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* FixGH-8562: SplFileObject::current() returns wrong value after next()
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.
ClosesGH-8562
* FixGH-8561: SplFileObject key()/current() desync after fgets()
fgets() read a line into the cache and incremented the line counter,
but left the cached line in place. The subsequent current() returned
the stale cached value instead of reading the next line from the
stream's actual position.
Clear the cached line after fgets() copies it to the return value.
This forces current() to re-read from the stream, which has already
advanced past the fgets'd line.
ClosesGH-8561
* FixGH-8563, GH-8564: SplFileObject EOF handling for seek() and next()
spl_filesystem_file_read_ex() treated a NULL buffer from
php_stream_get_line as a successful read of an empty line, creating a
phantom cached line at EOF. This caused seek() to give inconsistent
results between SplFileObject and SplTempFileObject (GH-8563), and
next() to increment the line counter indefinitely past EOF (GH-8564).
Return FAILURE when php_stream_get_line returns NULL, matching the
behavior of the existing php_stream_eof check. In seek(), break out
of the loop on EOF instead of returning, so the post-loop cleanup
runs consistently. In next(), return early at EOF without incrementing.
Make __toString() return empty string at EOF instead of throwing.
ClosesGH-8563ClosesGH-8564
* Refine fgets() to reuse cached line when present
When current() reads a line into the cache without advancing line_num,
a subsequent fgets() would re-read the stream and return the next line,
skipping the cached one and leaving key() out of sync with current()
for the rest of the iteration.
Use the cached line if present; otherwise read a fresh line. Either way,
advance line_num by one.
0 commit comments