Explicilty passing default value for escape in SplFileObject::fgetcsv changes outcome
Nobody has claimed this yet.
- Dominant language
- C
- Stars
- 40.4k
- Forks
- 8.1k
- Avg merge
- 2d 13h
- Merged PRs (30d)
- 96
Description
Description
The following code:
<?php
$file = new SplFileObject('php://memory', 'rw+');
$file->fwrite("foo;bar;baz");
$file->seek(0);
$file->setCsvControl(';', "\n");
while (!$file->eof()) {
$line = $file->fgetcsv(escape: '\\');
var_dump($line);
}
Resulted in this output:
array(1) {
[0]=>
string(11) "foo;bar;baz"
}
But I expected this output instead:
array(3) {
[0]=>
string(3) "foo"
[1]=>
string(3) "bar"
[2]=>
string(3) "baz"
}
For context, I am currently working on migrating a codebase from 8.2 to 8.4, and thought the safest option to keep existing behavior for fgetcsv calls would be to explicitly provide the current value of the default parameter, considering it will change in the next major version. I understand WHY it was implemented like this, but it is still a weird outcome. Ideally, the paramters for the method fgetcsv should be nullable, and default to null instead, so that the behavior is consistent with the way user land PHP functions and methods with default values for parameters work.
PHP Version
PHP 8.4.16 (cli) (built: Jan 13 2026 01:36:09) (NTS)
Copyright (c) The PHP Group
Built by https://github.com/docker-library/php
Zend Engine v4.4.16, Copyright (c) Zend Technologies
with Zend OPcache v8.4.16, Copyright (c), by Zend Technologies
Operating System
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the SplFileObject::fgetcsv entry point and reproduce the example using setCsvControl(';', "\n") with an explicitly passed escape value. Investigate whether nullable parameters can make omitted and explicit defaults consistent, then verify that the CSV is parsed into the requested three fields.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c, php
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100