php / php/php-src

Explicilty passing default value for escape in SplFileObject::fgetcsv changes outcome

Aperta
#22,156 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Bug Extension: spl Status: Verified
Lingua principale
C
Stelle
40.4k
Fork
8.2k
Merge medio
2g 13h
PR unite (30g)
96

Descrizione

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

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Partite dal punto di ingresso SplFileObject::fgetcsv e riproducete l’esempio usando setCsvControl(';', "\n") con un valore di escape passato esplicitamente. Verificate se i parametri nullable possono rendere coerenti i valori predefiniti omessi ed espliciti, quindi verificate che il CSV venga analizzato nei tre campi richiesti.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
c, php
Ambito
api, backend
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Tranquilla
Chiarezza
Abbastanza chiara
Idoneità per principianti
45/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.