Hi everyone,
Thank you for the feedback, and Artem, for the detailed review and independent verification of the implementation.
I think the discussion has raised two important questions: whether these improvements belong in the existing CSV API or a dedicated extension, and what an API supporting both files and already-open streams should look like.
Artem, your point about incremental improvements is fair. The RFC’s statement that the existing behaviour “cannot be fixed without breaking compatibility” is too broad. Several improvements could be introduced through additional functions or opt-in behaviour while preserving existing calls. You are also right that enclosing fields containing spaces is permitted by RFC 4180, and that locale-independent byte parsing has different implications for encodings such as Shift_JIS.
At the same time, PHP has taken the approach of introducing a modern API alongside an established one when their contracts differ substantially. The new DOM API, including Dom\Document, coexists with the legacy DOMDocument API, and the URI extension provides a dedicated API alongside parse_url(). These are relevant precedents for giving users clearer semantics without changing the behaviour of existing applications. Of course, those precedents do not automatically justify another CSV parser. They do suggest that improving the existing API and introducing a dedicated one are both reasonable approaches to evaluate. The question is whether the consistency and usability of the proposed CSV API justify its maintenance cost.
My motivation is to provide parsing, serialization, validation and file handling with consistent, explicit defaults. In particular, the file-based entry points accept a path and manage the underlying stream, covering the convenience previously provided by SplFileObject’s CSV methods. The existing fgetcsv()/fputcsv() functions operate on streams supplied by the caller. Both use cases deserve support.
Separately, the remaining overlapping-token writer issue reported on the PR has been addressed in https://github.com/php/php-src/commit/b7866156dc7e77304fe3419edceba6f890b113cb. Fields are now enclosed when tokens could form across field/separator boundaries. Distinguishable overlapping dialects remain supported; ambiguous combinations such as delimiter xy with enclosure xyx are rejected by both readers and writers. Regression tests cover both behaviours, and all 92 PHPT tests pass in my local verification.
With those concerns in mind, I would like to discuss three possible directions:
A. Improve the existing API in ext/standard, adding capabilities such as string serialization, multibyte tokens and opt-in strict parsing, with file and lazy-reading conveniences considered where needed.
B. Continue with the dedicated ext/csv proposal, retaining its function-based API and lazy collection, while adding entry points for existing streams and resolving the naming questions.
C. Rework the proposal around an object-oriented API in the Csv namespace, with explicit file and stream factories and writing methods. Stream ownership, iteration, validation and string conversion would need to be specified before this became a concrete voting option.
My preference remains a dedicated API with consistent semantics, but I am open to revising its shape or pursuing the existing-API route if that is the direction the project prefers.
Would a directional vote between these approaches be useful if discussion does not establish a clear preference? I would first document the alternatives and their trade-offs, and agree on the voting format. Selecting a direction would guide a revised proposal; it would not approve an API whose details have yet to be reviewed.
The current RFC does not propose deprecating the existing CSV functions. Any future consolidation would need its own discussion and an established migration path, rather than assuming that introducing a new API commits PHP to removing the old one.
The goal is to establish a maintainable CSV path for PHP users, including those migrating from the deprecated SplFileObject methods. I would welcome your thoughts on which direction best serves that goal.
Best regards,
Damian
···
Best regards,
Artem Ukrainskiy