Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

SplFileObject::fgetcsv() And fputcsv() Are Deprecated

SplFileObject::fgetcsv() and SplFileObject::fputcsv() read and write one CSV record on the wrapped file. In PHP 8.6, calling either method emits a deprecation notice recommending the plain fgetcsv()/fputcsv() functions on the underlying stream instead; both methods keep their previous behavior otherwise.

PHP code

<?php

file_put_contents(sys_get_temp_dir().'/splFileObjectCsvMethodsDeprecated86.csv', "a,b,c\n");

$file = new SplFileObject(sys_get_temp_dir().'/splFileObjectCsvMethodsDeprecated86.csv');
var_dump($file->fgetcsv());

$out = new SplFileObject(sys_get_temp_dir().'/splFileObjectCsvMethodsDeprecated86.out.csv', 'w');
var_dump($out->fputcsv(['x', 'y']));

unlink(sys_get_temp_dir().'/splFileObjectCsvMethodsDeprecated86.csv');
unlink(sys_get_temp_dir().'/splFileObjectCsvMethodsDeprecated86.out.csv');

?>

Before

PHP Deprecated:  SplFileObject::fgetcsv(): the $escape parameter must be provided, as its default value will change, either explicitly or via SplFileObject::setCsvControl() in /codes/splFileObjectCsvMethodsDeprecated86.php on line 6

Deprecated: SplFileObject::fgetcsv(): the $escape parameter must be provided, as its default value will change, either explicitly or via SplFileObject::setCsvControl() in /codes/splFileObjectCsvMethodsDeprecated86.php on line 6
array(3) {
  [0]=>
  string(1) "a" 
  [1]=>
  string(1) "b" 
  [2]=>
  string(1) "c" 
}
PHP Deprecated:  SplFileObject::fputcsv(): the $escape parameter must be provided, as its default value will change, either explicitly or via SplFileObject::setCsvControl() in /codes/splFileObjectCsvMethodsDeprecated86.php on line 9

Deprecated: SplFileObject::fputcsv(): the $escape parameter must be provided, as its default value will change, either explicitly or via SplFileObject::setCsvControl() in /codes/splFileObjectCsvMethodsDeprecated86.php on line 9
int(4)

After

PHP Deprecated:  Method SplFileObject::fgetcsv() is deprecated since 8.6 in /codes/splFileObjectCsvMethodsDeprecated86.php on line 6

Deprecated: Method SplFileObject::fgetcsv() is deprecated since 8.6 in /codes/splFileObjectCsvMethodsDeprecated86.php on line 6
PHP Deprecated:  SplFileObject::fgetcsv(): the $escape parameter must be provided, as its default value will change, either explicitly or via SplFileObject::setCsvControl() in /codes/splFileObjectCsvMethodsDeprecated86.php on line 6

Deprecated: SplFileObject::fgetcsv(): the $escape parameter must be provided, as its default value will change, either explicitly or via SplFileObject::setCsvControl() in /codes/splFileObjectCsvMethodsDeprecated86.php on line 6
array(3) {
  [0]=>
  string(1) "a" 
  [1]=>
  string(1) "b" 
  [2]=>
  string(1) "c" 
}
PHP Deprecated:  Method SplFileObject::fputcsv() is deprecated since 8.6 in /codes/splFileObjectCsvMethodsDeprecated86.php on line 9

Deprecated: Method SplFileObject::fputcsv() is deprecated since 8.6 in /codes/splFileObjectCsvMethodsDeprecated86.php on line 9
PHP Deprecated:  SplFileObject::fputcsv(): the $escape parameter must be provided, as its default value will change, either explicitly or via SplFileObject::setCsvControl() in /codes/splFileObjectCsvMethodsDeprecated86.php on line 9

Deprecated: SplFileObject::fputcsv(): the $escape parameter must be provided, as its default value will change, either explicitly or via SplFileObject::setCsvControl() in /codes/splFileObjectCsvMethodsDeprecated86.php on line 9
int(4)

PHP version change

This behavior was deprecated in 8.6.

This behavior changed in .

See Also

Error Messages

Extension

© 2023-2026, Damien Seguy - Exakat