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