1--TEST--
2SplFileObject::fputcsv(): functionality tests
3--FILE--
4<?php
5$file = __DIR__ . '/SplFileObject_fputcsv.csv';
6$fo = new SplFileObject($file, 'w');
7// Suppress deprecation notice
8$fo->setCsvControl(escape: '\\');
9
10$list = array (
11  0 => 'aaa,bbb',
12  1 => 'aaa,"bbb"',
13  2 => '"aaa","bbb"',
14  3 => 'aaa,bbb',
15  4 => '"aaa",bbb',
16  5 => '"aaa",   "bbb"',
17  6 => ',',
18  7 => 'aaa,',
19  8 => ',"aaa"',
20  9 => '"",""',
21  10 => '"""""",',
22  11 => '""""",aaa',
23  12 => 'aaa,bbb   ',
24  13 => 'aaa,"bbb   "',
25  14 => 'aaa"aaa","bbb"bbb',
26  15 => 'aaa"aaa""",bbb',
27  16 => 'aaa,"\\"bbb,ccc',
28  17 => 'aaa"\\"a","bbb"',
29  18 => '"\\"","aaa"',
30  19 => '"\\""",aaa',
31);
32
33foreach ($list as $v) {
34    $fo->fputcsv(explode(',', $v));
35}
36unset($fo);
37
38$res = file($file);
39foreach($res as &$val)
40{
41    $val = substr($val, 0, -1);
42}
43echo '$list = ';var_export($res);echo ";\n";
44
45$fp = fopen($file, "r");
46$res = array();
47while($l=fgetcsv($fp, escape: '\\'))
48{
49    $res[] = join(',',$l);
50}
51fclose($fp);
52
53echo '$list = ';var_export($res);echo ";\n";
54
55?>
56--CLEAN--
57<?php
58$file = __DIR__ . '/SplFileObject_fputcsv.csv';
59unlink($file);
60?>
61--EXPECT--
62$list = array (
63  0 => 'aaa,bbb',
64  1 => 'aaa,"""bbb"""',
65  2 => '"""aaa""","""bbb"""',
66  3 => 'aaa,bbb',
67  4 => '"""aaa""",bbb',
68  5 => '"""aaa""","   ""bbb"""',
69  6 => ',',
70  7 => 'aaa,',
71  8 => ',"""aaa"""',
72  9 => '"""""",""""""',
73  10 => '"""""""""""""",',
74  11 => '"""""""""""",aaa',
75  12 => 'aaa,"bbb   "',
76  13 => 'aaa,"""bbb   """',
77  14 => '"aaa""aaa""","""bbb""bbb"',
78  15 => '"aaa""aaa""""""",bbb',
79  16 => 'aaa,"""\\"bbb",ccc',
80  17 => '"aaa""\\"a""","""bbb"""',
81  18 => '"""\\"""","""aaa"""',
82  19 => '"""\\"""""",aaa',
83);
84$list = array (
85  0 => 'aaa,bbb',
86  1 => 'aaa,"bbb"',
87  2 => '"aaa","bbb"',
88  3 => 'aaa,bbb',
89  4 => '"aaa",bbb',
90  5 => '"aaa",   "bbb"',
91  6 => ',',
92  7 => 'aaa,',
93  8 => ',"aaa"',
94  9 => '"",""',
95  10 => '"""""",',
96  11 => '""""",aaa',
97  12 => 'aaa,bbb   ',
98  13 => 'aaa,"bbb   "',
99  14 => 'aaa"aaa","bbb"bbb',
100  15 => 'aaa"aaa""",bbb',
101  16 => 'aaa,"\\"bbb,ccc',
102  17 => 'aaa"\\"a","bbb"',
103  18 => '"\\"","aaa"',
104  19 => '"\\""",aaa',
105);
106