Explicilty passing default value for escape in SplFileObject::fgetcsv changes outcome
まだ誰も着手していません。
- 主要言語
- C
- スター
- 40.4k
- フォーク
- 8.2k
- 平均マージ
- 2日 13時間
- マージ済み PR(30日)
- 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 にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
SplFileObject::fgetcsv のエントリポイントから開始し、エスケープ値を明示的に渡して setCsvControl(';', "\n") を使用する例を再現します。nullable パラメータによって、省略したデフォルト値と明示的に指定したデフォルト値を一貫させられるかを調査し、その後、CSV が要求された 3 つのフィールドにパースされることを確認します。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- c, php
- 領域
- api, backend
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 静か
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 45/100