php-src/ext/spl/tests/SplFileObject_fgetcsv_enclosure_error.phpt
Nikita Popov 625d8463a4 Consistent error handling for fgetcsv/fputcsv
Normalize the behavior between the file functions and those on
SplFileObject.

Be consistent about throwing regardless of whether the delimiter etc
is empty or has too many characters. I don't think it's worthwhile
to distinguish these cases.

Back when we looked into this originally, there was some hope that
we might want to add support for multiple-character delimiter etc,
but after a cursory look, I really don't think this is going to
happen (for fputcsv maybe, but for fgetcsv this just makes an already
broken function much more complicated.)

Closes GH-6188.
2020-09-23 10:11:04 +02:00

26 lines
537 B
PHP

--TEST--
SplFileObject::fgetcsv with alternative delimiter
--FILE--
<?php
$fp = fopen('SplFileObject__fgetcsv5.csv', 'w+');
fputcsv($fp, array(
'field1',
'field2',
'field3',
5
), ',', '"');
fclose($fp);
$fo = new SplFileObject('SplFileObject__fgetcsv5.csv');
try {
var_dump($fo->fgetcsv(',', 'invalid'));
} catch (ValueError $e) {
echo $e->getMessage(), "\n";
}
?>
--CLEAN--
<?php
unlink('SplFileObject__fgetcsv5.csv');
?>
--EXPECT--
SplFileObject::fgetcsv(): Argument #2 ($enclosure) must be a single character