Skip to content

Allow configuring escape for CsvWriter#17

Merged
slashrsm merged 2 commits into
masterfrom
fix/csv-writer-escape
Jul 23, 2026
Merged

Allow configuring escape for CsvWriter#17
slashrsm merged 2 commits into
masterfrom
fix/csv-writer-escape

Conversation

@slashrsm

Copy link
Copy Markdown
Contributor

Summary

Supersedes #10 — rebased onto current master (3.0.0 / PHP ^8.2) and covered with PHPUnit.

PHP 8.4 deprecates fputcsv() calls that do not pass an explicit $escape argument. Without this change it is impossible to avoid a deprecation when using CsvWriter (and PHPUnit with convertDeprecationsToExceptions fails the whole writer suite on 8.4+).

Changes

  • Add optional 6th constructor arg $escape (typed string, default '\\' for BC — same as Allow configuring escape for CsvWriter #10 / CsvReader)
  • Pass $escape as the 5th argument to both fputcsv() calls in writeItem()
  • Callers can pass '' for the PHP-preferred modern “no escape” behavior

If a future major bumps the default to '', that can be done then; this keeps BC for 3.x.

Tests

  • testEscapeParameterAffectsOutput — default \\ vs '' produce different CSV for a field with backslash+quote; each matches a direct fputcsv() reference
  • testEmptyEscapeWritesWithoutDeprecation — empty escape writes multi-row CSV without PHP 8.4+ deprecation exceptions
  • Existing writer tests now pass on PHP 8.4/8.5 (they previously failed solely due to the deprecation)

Checklist

PHP 8.4 deprecates fputcsv() calls that omit the $escape argument.
Add an optional constructor parameter (default '\\' for BC) and pass it
through to fputcsv so callers can silence the deprecation and control
escape behavior (including empty string for modern "no escape" CSV).

Adds PHPUnit coverage that proves escape is applied and that writing
works without deprecation exceptions under convertDeprecationsToExceptions.

Supersedes #10.
@slashrsm

Copy link
Copy Markdown
Contributor Author

Supersedes #10. Requesting review.

@slashrsm slashrsm closed this Jul 23, 2026
@slashrsm slashrsm reopened this Jul 23, 2026
@slashrsm

Copy link
Copy Markdown
Contributor Author

@copilot please review this PR.

@slashrsm
slashrsm merged commit e3f743d into master Jul 23, 2026
4 checks passed
Copilot stopped work on behalf of slashrsm due to an error July 23, 2026 08:37
@slashrsm
slashrsm deleted the fix/csv-writer-escape branch July 23, 2026 08:37
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.

1 participant