15 Commits
Author SHA1 Message Date
Gina Peter Banyard ac3ff655ea spl: deprecate SplFileObject CSV methods (#23437)
RFC: https://wiki.php.net/rfc/deprecations_php_8_6#deprecate_splfileobject_csv_methods
2026-08-25 11:03:22 +01:00
NickSdot 06a5a1f6d3 ext/spl: applied fixers to improve test robustness (#23058) 2026-08-07 13:47:53 +01:00
Ilia Alshanetsky 9a530a1c5e Fix GH-21742: SplFileObject::fgets() throws at EOF in eof/fgets loop (#21853)
The SplFileObject iterator-desync fix in 08dad09702 made
spl_filesystem_file_read_ex throw "Cannot read from file" on the
NULL-buffer path. SplFileObject::fgets() now throws inside the
documented while (!$spl->eof()) $spl->fgets() idiom, because eof()
returns false until a read attempt returns zero bytes.

Keep the stricter semantics for next(), seek(), current(), fscanf().
Narrow fgets() to silent=true and return empty string on FAILURE,
restoring the PHP-8.5 contract.

Fixes GH-21742
2026-04-23 17:55:15 +01:00
Ilia Alshanetsky 08dad09702 Fix GH-8561, GH-8562, GH-8563, GH-8564: SplFileObject iterator desync (#21679)
* Fix GH-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.

Closes GH-8562

* Fix GH-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.

Closes GH-8561

* Fix GH-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.

Closes GH-8563
Closes GH-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.
2026-04-13 11:35:20 +01:00
Gina Peter Banyard f756b96e06 Make CSV deprecation less annoying to deal with (#15569) 2024-09-13 15:07:26 +01:00
Gina Peter Banyard c818d944cf ext/(standard|spl): Deprecate passing a non-empty string as the $enclosure parameter (#15362) 2024-08-12 16:09:56 +01:00
George Peter Banyard 7ab22aad9e Refactor code handling file.current_zval (#8934)
The Zval is always an array
2022-07-28 19:36:30 +01:00
Ilija Tovilo b5ab0e06b8 Assert all test files are cleaned up in CI (#8977)
Closes GH-8427
2022-07-21 16:06:14 +01:00
George Peter Banyard 6f26102bbf Merge branch 'PHP-8.1'
* PHP-8.1:
  Revert "Fix GH-8563  Different results for seek() on SplFileObject and SplTempFileObject"
  Revert "Update FreeBSD CI image."
2022-07-05 21:45:13 +01:00
George Peter Banyard 79a283240e Revert "Fix GH-8563 Different results for seek() on SplFileObject and SplTempFileObject"
Although the fix is partially correct it also breaks long standing behaviour which has been produced since PHP 5.3.

This reverts commit 6f87a5c633.
2022-07-05 21:28:59 +01:00
George Peter Banyard 8c50b8d797 Merge branch 'PHP-8.1'
* PHP-8.1:
  Fix GH-8563  Different results for seek() on SplFileObject and SplTempFileObject
2022-06-20 12:53:26 +01:00
George Peter Banyard 080fde2605 Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0:
  Fix GH-8563  Different results for seek() on SplFileObject and SplTempFileObject
2022-06-20 12:53:01 +01:00
George Peter Banyard 6f87a5c633 Fix GH-8563 Different results for seek() on SplFileObject and SplTempFileObject
With memory streams if we get a NULL buffer we must not instantiate an empty line
2022-06-20 12:47:37 +01:00
George Peter Banyard fcba0a49fc Fix test file name to not include a whitespace
This breaks the preload file flag in the test runner
2022-05-31 11:28:01 +01:00
George Peter Banyard fc799ecdbe Move SplFileObject tests into subfolder 2022-05-27 18:33:48 +01:00