Explicilty passing default value for escape in SplFileObject::fgetcsv changes outcome
还没有人认领这个 Issue。
- 主要语言
- C
- 星标
- 40.4k
- 派生
- 8.1k
- 平均合并
- 2 天 13 小时
- 30 天内合并 PR
- 96
描述
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
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从 SplFileObject::fgetcsv 入口点开始,使用显式传入的转义值通过 setCsvControl(';', "\n") 重现该示例。调查 nullable 参数是否可以使省略的默认值和显式指定的默认值保持一致,然后验证 CSV 是否被解析为所请求的三个字段。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- c, php
- 领域
- api, backend
- Issue 类型
- 缺陷
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 冷清
- 描述清晰度
- 基本清楚
- 新手友好度
- 45/100