xref: /PHP-8.3/ext/spl/tests/gh13685.phpt (revision aa34e0ac)
1--TEST--
2GH-13685 (Unexpected null pointer in zend_string.h)
3--FILE--
4<?php
5
6$contents = <<<EOS
7"A", "B", "C"
8"D", "E", "F"
9EOS;
10
11echo "--- Directly call fgetcsv ---\n";
12
13$file = new SplTempFileObject;
14$file->fwrite($contents);
15$file->rewind();
16while (($data = $file->fgetcsv(',', '"', ''))) {
17    var_dump((string) $file);
18}
19try {
20    var_dump((string) $file);
21} catch (Exception $e) {
22    echo $e->getMessage(), "\n";
23}
24
25echo "--- Use csv control ---\n";
26
27$file = new SplTempFileObject;
28$file->fwrite($contents);
29$file->rewind();
30$file->setFlags(SplFileObject::READ_CSV);
31$file->setCsvControl(',', '"', '');
32foreach ($file as $row) {
33    var_dump((string) $file);
34}
35try {
36    var_dump((string) $file);
37} catch (Exception $e) {
38    echo $e->getMessage(), "\n";
39}
40
41?>
42--EXPECT--
43--- Directly call fgetcsv ---
44string(14) ""A", "B", "C"
45"
46string(13) ""D", "E", "F""
47Cannot read from file php://temp
48--- Use csv control ---
49string(14) ""A", "B", "C"
50"
51string(13) ""D", "E", "F""
52Cannot read from file php://temp
53