3v4l.org

run code in 300+ PHP versions simultaneously
<?php $flagList = [ 'DROP_NEW_LINE' => SplFileObject::DROP_NEW_LINE, 'READ_AHEAD' => SplFileObject::READ_AHEAD, 'SKIP_EMPTY' => SplFileObject::SKIP_EMPTY, 'READ_AHEAD-DROP_NEW_LINE' => SplFileObject::READ_AHEAD | SplFileObject::DROP_NEW_LINE, 'READ_AHEAD-SKIP_EMPTY' => SplFileObject::READ_AHEAD | SplFileObject::SKIP_EMPTY, 'DROP_NEW_LINE-SKIP_EMPTY' => SplFileObject::DROP_NEW_LINE | SplFileObject::SKIP_EMPTY, 'READ_AHEAD-SKIP_EMPTY-DROP_NEW_LINE' => SplFileObject::READ_AHEAD | SplFileObject::DROP_NEW_LINE | SplFileObject::SKIP_EMPTY, ]; $file = new SplFileObject('/tmp/test.csv', 'w+'); $file->fwrite("1st\n\n2nd\n"); foreach ($flagList as $type => $flag) { $file->setFlags(SplFileObject::READ_CSV | $flag); if ($file->fgetcsv() === null) { echo $type . ' flag makes fgetcsv return NULL' . PHP_EOL; } }
Output for 8.1.0 - 8.1.6
Output for 7.3.0 - 7.3.33, 7.4.0 - 7.4.29, 8.0.0 - 8.0.19
READ_AHEAD flag makes fgetcsv return NULL SKIP_EMPTY flag makes fgetcsv return NULL READ_AHEAD-DROP_NEW_LINE flag makes fgetcsv return NULL READ_AHEAD-SKIP_EMPTY flag makes fgetcsv return NULL DROP_NEW_LINE-SKIP_EMPTY flag makes fgetcsv return NULL READ_AHEAD-SKIP_EMPTY-DROP_NEW_LINE flag makes fgetcsv return NULL

preferences:
52.98 ms | 411 KiB | 5 Q