3v4l.org

run code in 300+ PHP versions simultaneously
<?php $temp = tempnam(sys_get_temp_dir(), 'csv_bug'); file_put_contents($temp, <<<'CSV' first,second foo,bar "foo baz",bar baz,bar CSV ); $expected = array( array('first', 'second'), array('foo', 'bar'), array("foo\nbaz", 'bar'), array('baz', 'bar'), ); $cases = array( 'drop newline' => \SplFileObject::DROP_NEW_LINE, 'skip empty' => \SplFileObject::SKIP_EMPTY, 'skip empty + read ahead' => \SplFileObject::SKIP_EMPTY | \SplFileObject::READ_AHEAD, 'drop newline + read ahead' => \SplFileObject::DROP_NEW_LINE | \SplFileObject::READ_AHEAD, 'drop newline + skip empty' => \SplFileObject::DROP_NEW_LINE | \SplFileObject::SKIP_EMPTY, 'all' => \SplFileObject::DROP_NEW_LINE | \SplFileObject::SKIP_EMPTY | \SplFileObject::READ_AHEAD, ); foreach ($cases as $name => $flags) { $file = new SplFileObject($temp); $file->setFlags($flags | \SplFileObject::READ_CSV); echo $name, "\n" var_dump(iterator_to_array($file, false)); } var_dump('expected', $expected);
Output for 7.1.25 - 7.1.30, 7.2.0 - 7.2.19, 7.3.0 - 7.3.6
Parse error: syntax error, unexpected 'var_dump' (T_STRING), expecting ',' or ';' in /in/7uQvB on line 35
Process exited with code 255.

preferences:
182.59 ms | 1400 KiB | 40 Q