php-src/ext/spl/tests/SplFileObject_setCsvControl_error003.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

29 lines
636 B
PHP

--TEST--
SPL: SplFileObject::setCsvControl error 003
--CREDITS--
Erwin Poeze <erwin.poeze at gmail.com>
--INI--
include_path=.
--FILE--
<?php
file_put_contents('csv_control_data_error003.csv',
<<<CDATA
'groene appelen'|10
'gele bananen'|20
'rode kersen'|30
CDATA
);
$s = new SplFileObject('csv_control_data_error003.csv');
$s->setFlags(SplFileObject::READ_CSV);
try {
$s->setCsvControl('|', '\'', 'three');
} catch (ValueError $e) {
echo $e->getMessage(), "\n";
}
?>
--CLEAN--
<?php
unlink('csv_control_data_error003.csv');
?>
--EXPECT--
SplFileObject::setCsvControl(): Argument #3 ($escape) must be empty or a single character