1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
|
--TEST--
Various fgetcsv() error conditions
--FILE--
<?php
$file_name = __DIR__ . '/fgetcsv_error_conditions.csv';
$file_handle = fopen($file_name, 'r');
$length = 1024;
$delimiter = ',';
$enclosure = '"';
echo 'fgetcsv() with negative length' . \PHP_EOL;
try {
var_dump( fgetcsv($file_handle, -10, escape: "\\") );
} catch (\ValueError $e) {
echo $e->getMessage() . \PHP_EOL;
}
try {
var_dump( fgetcsv($file_handle, -10, $delimiter, escape: "\\") );
} catch (\ValueError $e) {
echo $e->getMessage() . \PHP_EOL;
}
try {
var_dump( fgetcsv($file_handle, -10, $delimiter, $enclosure, escape: "\\") );
} catch (\ValueError $e) {
echo $e->getMessage() . \PHP_EOL;
}
echo 'fgetcsv() with delimiter as empty string' . \PHP_EOL;
try {
var_dump( fgetcsv($file_handle, $length, '', $enclosure, escape: "\\") );
} catch (\ValueError $e) {
echo $e->getMessage() . \PHP_EOL;
}
echo 'fgetcsv() with enclosure as empty string' . \PHP_EOL;
try {
var_dump( fgetcsv($file_handle, $length, $delimiter, '', escape: "\\") );
} catch (\ValueError $e) {
echo $e->getMessage() . \PHP_EOL;
}
echo 'fgetcsv() with delimiter & enclosure as empty string' . \PHP_EOL;
try {
var_dump( fgetcsv($file_handle, $length, '', '', escape: "\\") );
} catch (\ValueError $e) {
echo $e->getMessage() . \PHP_EOL;
}
?>
--EXPECTF--
fgetcsv() with negative length
fgetcsv(): Argument #2 ($length) must be between 0 and %d
fgetcsv(): Argument #2 ($length) must be between 0 and %d
fgetcsv(): Argument #2 ($length) must be between 0 and %d
fgetcsv() with delimiter as empty string
fgetcsv(): Argument #3 ($separator) must be a single character
fgetcsv() with enclosure as empty string
fgetcsv(): Argument #4 ($enclosure) must be a single character
fgetcsv() with delimiter & enclosure as empty string
fgetcsv(): Argument #3 ($separator) must be a single character
|