1--TEST--
2Test fgetcsv() : usage variations - reading files opened in write only mode (Bug #42036)
3--FILE--
4<?php
5/*
6 Prototype: array fgetcsv ( resource $handle [, int $length [, string $delimiter [, string $enclosure]]] );
7 Description: Gets line from file pointer and parse for CSV fields
8*/
9
10/* Testing fgetcsv() to read from files opened in write only mode */
11
12echo "*** Testing fgetcsv() : reading the files opened in write only mode ***\n";
13
14/* the array is with three elements in it. Each element should be read as
15   1st element is delimiter, 2nd element is enclosure
16   and 3rd element is csv fields
17*/
18$csv_lists = array (
19  array(',', '"', '"water",fruit'),
20  array(',', '"', '"water","fruit"'),
21  array(' ', '^', '^water^ ^fruit^'),
22  array(':', '&', '&water&:&fruit&'),
23  array('=', '=', '=water===fruit='),
24  array('-', '-', '-water--fruit-air'),
25  array('-', '-', '-water---fruit---air-'),
26  array(':', '&', '&""""&:&"&:,:":&,&:,,,,')
27);
28
29$filename = __DIR__ . '/fgetcsv_variation26.tmp';
30@unlink($filename);
31
32$file_modes = array ("w", "wb", "wt",
33                     "a", "ab", "at",
34                     "x", "xb", "xt");
35
36$loop_counter = 1;
37foreach ($csv_lists as $csv_list) {
38  for($mode_counter = 0; $mode_counter < count($file_modes); $mode_counter++) {
39    // create the file and add the content with has csv fields
40    $file_handle = fopen($filename, $file_modes[$mode_counter] );
41
42    if ( !$file_handle ) {
43      echo "Error: failed to create file $filename!\n";
44      exit();
45    }
46    $delimiter = $csv_list[0];
47    $enclosure = $csv_list[1];
48    $csv_field = $csv_list[2];
49
50    fwrite($file_handle, $csv_field . "\n");
51    // write another line of text and a blank line
52    // this will be used to test, if the fgetcsv() read more than a line and its
53    // working when only a blank line is read
54    fwrite($file_handle, "This is line of text without csv fields\n");
55    fwrite($file_handle, "\n"); // blank line
56
57    // rewind the file pointer to bof
58      rewind($file_handle);
59
60    echo "\n-- Testing fgetcsv() with file opened using $file_modes[$mode_counter] mode --\n";
61
62    // call fgetcsv() to parse csv fields
63
64    // use the right delimiter and enclosure with max length
65    var_dump( fgetcsv($file_handle, 1024, $delimiter, $enclosure) );
66    // check the file pointer position and if eof
67    var_dump( ftell($file_handle) );
68    var_dump( feof($file_handle) );
69
70    // close the file
71    fclose($file_handle);
72    //delete file
73    unlink($filename);
74  } //end of mode loop
75} // end of foreach
76
77echo "Done\n";
78?>
79--EXPECTF--
80*** Testing fgetcsv() : reading the files opened in write only mode ***
81
82-- Testing fgetcsv() with file opened using w mode --
83
84Notice: fgetcsv(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
85bool(false)
86int(0)
87bool(false)
88
89-- Testing fgetcsv() with file opened using wb mode --
90
91Notice: fgetcsv(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
92bool(false)
93int(0)
94bool(false)
95
96-- Testing fgetcsv() with file opened using wt mode --
97
98Notice: fgetcsv(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
99bool(false)
100int(0)
101bool(false)
102
103-- Testing fgetcsv() with file opened using a mode --
104
105Notice: fgetcsv(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
106bool(false)
107int(0)
108bool(false)
109
110-- Testing fgetcsv() with file opened using ab mode --
111
112Notice: fgetcsv(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
113bool(false)
114int(0)
115bool(false)
116
117-- Testing fgetcsv() with file opened using at mode --
118
119Notice: fgetcsv(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
120bool(false)
121int(0)
122bool(false)
123
124-- Testing fgetcsv() with file opened using x mode --
125
126Notice: fgetcsv(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
127bool(false)
128int(0)
129bool(false)
130
131-- Testing fgetcsv() with file opened using xb mode --
132
133Notice: fgetcsv(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
134bool(false)
135int(0)
136bool(false)
137
138-- Testing fgetcsv() with file opened using xt mode --
139
140Notice: fgetcsv(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
141bool(false)
142int(0)
143bool(false)
144
145-- Testing fgetcsv() with file opened using w mode --
146
147Notice: fgetcsv(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
148bool(false)
149int(0)
150bool(false)
151
152-- Testing fgetcsv() with file opened using wb mode --
153
154Notice: fgetcsv(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
155bool(false)
156int(0)
157bool(false)
158
159-- Testing fgetcsv() with file opened using wt mode --
160
161Notice: fgetcsv(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
162bool(false)
163int(0)
164bool(false)
165
166-- Testing fgetcsv() with file opened using a mode --
167
168Notice: fgetcsv(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
169bool(false)
170int(0)
171bool(false)
172
173-- Testing fgetcsv() with file opened using ab mode --
174
175Notice: fgetcsv(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
176bool(false)
177int(0)
178bool(false)
179
180-- Testing fgetcsv() with file opened using at mode --
181
182Notice: fgetcsv(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
183bool(false)
184int(0)
185bool(false)
186
187-- Testing fgetcsv() with file opened using x mode --
188
189Notice: fgetcsv(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
190bool(false)
191int(0)
192bool(false)
193
194-- Testing fgetcsv() with file opened using xb mode --
195
196Notice: fgetcsv(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
197bool(false)
198int(0)
199bool(false)
200
201-- Testing fgetcsv() with file opened using xt mode --
202
203Notice: fgetcsv(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
204bool(false)
205int(0)
206bool(false)
207
208-- Testing fgetcsv() with file opened using w mode --
209
210Notice: fgetcsv(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
211bool(false)
212int(0)
213bool(false)
214
215-- Testing fgetcsv() with file opened using wb mode --
216
217Notice: fgetcsv(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
218bool(false)
219int(0)
220bool(false)
221
222-- Testing fgetcsv() with file opened using wt mode --
223
224Notice: fgetcsv(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
225bool(false)
226int(0)
227bool(false)
228
229-- Testing fgetcsv() with file opened using a mode --
230
231Notice: fgetcsv(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
232bool(false)
233int(0)
234bool(false)
235
236-- Testing fgetcsv() with file opened using ab mode --
237
238Notice: fgetcsv(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
239bool(false)
240int(0)
241bool(false)
242
243-- Testing fgetcsv() with file opened using at mode --
244
245Notice: fgetcsv(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
246bool(false)
247int(0)
248bool(false)
249
250-- Testing fgetcsv() with file opened using x mode --
251
252Notice: fgetcsv(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
253bool(false)
254int(0)
255bool(false)
256
257-- Testing fgetcsv() with file opened using xb mode --
258
259Notice: fgetcsv(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
260bool(false)
261int(0)
262bool(false)
263
264-- Testing fgetcsv() with file opened using xt mode --
265
266Notice: fgetcsv(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
267bool(false)
268int(0)
269bool(false)
270
271-- Testing fgetcsv() with file opened using w mode --
272
273Notice: fgetcsv(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
274bool(false)
275int(0)
276bool(false)
277
278-- Testing fgetcsv() with file opened using wb mode --
279
280Notice: fgetcsv(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
281bool(false)
282int(0)
283bool(false)
284
285-- Testing fgetcsv() with file opened using wt mode --
286
287Notice: fgetcsv(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
288bool(false)
289int(0)
290bool(false)
291
292-- Testing fgetcsv() with file opened using a mode --
293
294Notice: fgetcsv(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
295bool(false)
296int(0)
297bool(false)
298
299-- Testing fgetcsv() with file opened using ab mode --
300
301Notice: fgetcsv(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
302bool(false)
303int(0)
304bool(false)
305
306-- Testing fgetcsv() with file opened using at mode --
307
308Notice: fgetcsv(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
309bool(false)
310int(0)
311bool(false)
312
313-- Testing fgetcsv() with file opened using x mode --
314
315Notice: fgetcsv(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
316bool(false)
317int(0)
318bool(false)
319
320-- Testing fgetcsv() with file opened using xb mode --
321
322Notice: fgetcsv(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
323bool(false)
324int(0)
325bool(false)
326
327-- Testing fgetcsv() with file opened using xt mode --
328
329Notice: fgetcsv(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
330bool(false)
331int(0)
332bool(false)
333
334-- Testing fgetcsv() with file opened using w mode --
335
336Notice: fgetcsv(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
337bool(false)
338int(0)
339bool(false)
340
341-- Testing fgetcsv() with file opened using wb mode --
342
343Notice: fgetcsv(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
344bool(false)
345int(0)
346bool(false)
347
348-- Testing fgetcsv() with file opened using wt mode --
349
350Notice: fgetcsv(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
351bool(false)
352int(0)
353bool(false)
354
355-- Testing fgetcsv() with file opened using a mode --
356
357Notice: fgetcsv(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
358bool(false)
359int(0)
360bool(false)
361
362-- Testing fgetcsv() with file opened using ab mode --
363
364Notice: fgetcsv(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
365bool(false)
366int(0)
367bool(false)
368
369-- Testing fgetcsv() with file opened using at mode --
370
371Notice: fgetcsv(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
372bool(false)
373int(0)
374bool(false)
375
376-- Testing fgetcsv() with file opened using x mode --
377
378Notice: fgetcsv(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
379bool(false)
380int(0)
381bool(false)
382
383-- Testing fgetcsv() with file opened using xb mode --
384
385Notice: fgetcsv(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
386bool(false)
387int(0)
388bool(false)
389
390-- Testing fgetcsv() with file opened using xt mode --
391
392Notice: fgetcsv(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
393bool(false)
394int(0)
395bool(false)
396
397-- Testing fgetcsv() with file opened using w mode --
398
399Notice: fgetcsv(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
400bool(false)
401int(0)
402bool(false)
403
404-- Testing fgetcsv() with file opened using wb mode --
405
406Notice: fgetcsv(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
407bool(false)
408int(0)
409bool(false)
410
411-- Testing fgetcsv() with file opened using wt mode --
412
413Notice: fgetcsv(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
414bool(false)
415int(0)
416bool(false)
417
418-- Testing fgetcsv() with file opened using a mode --
419
420Notice: fgetcsv(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
421bool(false)
422int(0)
423bool(false)
424
425-- Testing fgetcsv() with file opened using ab mode --
426
427Notice: fgetcsv(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
428bool(false)
429int(0)
430bool(false)
431
432-- Testing fgetcsv() with file opened using at mode --
433
434Notice: fgetcsv(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
435bool(false)
436int(0)
437bool(false)
438
439-- Testing fgetcsv() with file opened using x mode --
440
441Notice: fgetcsv(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
442bool(false)
443int(0)
444bool(false)
445
446-- Testing fgetcsv() with file opened using xb mode --
447
448Notice: fgetcsv(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
449bool(false)
450int(0)
451bool(false)
452
453-- Testing fgetcsv() with file opened using xt mode --
454
455Notice: fgetcsv(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
456bool(false)
457int(0)
458bool(false)
459
460-- Testing fgetcsv() with file opened using w mode --
461
462Notice: fgetcsv(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
463bool(false)
464int(0)
465bool(false)
466
467-- Testing fgetcsv() with file opened using wb mode --
468
469Notice: fgetcsv(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
470bool(false)
471int(0)
472bool(false)
473
474-- Testing fgetcsv() with file opened using wt mode --
475
476Notice: fgetcsv(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
477bool(false)
478int(0)
479bool(false)
480
481-- Testing fgetcsv() with file opened using a mode --
482
483Notice: fgetcsv(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
484bool(false)
485int(0)
486bool(false)
487
488-- Testing fgetcsv() with file opened using ab mode --
489
490Notice: fgetcsv(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
491bool(false)
492int(0)
493bool(false)
494
495-- Testing fgetcsv() with file opened using at mode --
496
497Notice: fgetcsv(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
498bool(false)
499int(0)
500bool(false)
501
502-- Testing fgetcsv() with file opened using x mode --
503
504Notice: fgetcsv(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
505bool(false)
506int(0)
507bool(false)
508
509-- Testing fgetcsv() with file opened using xb mode --
510
511Notice: fgetcsv(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
512bool(false)
513int(0)
514bool(false)
515
516-- Testing fgetcsv() with file opened using xt mode --
517
518Notice: fgetcsv(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
519bool(false)
520int(0)
521bool(false)
522
523-- Testing fgetcsv() with file opened using w mode --
524
525Notice: fgetcsv(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
526bool(false)
527int(0)
528bool(false)
529
530-- Testing fgetcsv() with file opened using wb mode --
531
532Notice: fgetcsv(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
533bool(false)
534int(0)
535bool(false)
536
537-- Testing fgetcsv() with file opened using wt mode --
538
539Notice: fgetcsv(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
540bool(false)
541int(0)
542bool(false)
543
544-- Testing fgetcsv() with file opened using a mode --
545
546Notice: fgetcsv(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
547bool(false)
548int(0)
549bool(false)
550
551-- Testing fgetcsv() with file opened using ab mode --
552
553Notice: fgetcsv(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
554bool(false)
555int(0)
556bool(false)
557
558-- Testing fgetcsv() with file opened using at mode --
559
560Notice: fgetcsv(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
561bool(false)
562int(0)
563bool(false)
564
565-- Testing fgetcsv() with file opened using x mode --
566
567Notice: fgetcsv(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
568bool(false)
569int(0)
570bool(false)
571
572-- Testing fgetcsv() with file opened using xb mode --
573
574Notice: fgetcsv(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
575bool(false)
576int(0)
577bool(false)
578
579-- Testing fgetcsv() with file opened using xt mode --
580
581Notice: fgetcsv(): read of 8192 bytes failed with errno=9 Bad file descriptor in %s on line %d
582bool(false)
583int(0)
584bool(false)
585Done
586