[php-src] Issue #13916: SplFileObject: foreach doesn't start from the correct line after `SplFileObject::seek()`

From: Date: Mon, 08 Apr 2024 13:46:22 +0000
Subject: [php-src] Issue #13916: SplFileObject: foreach doesn't start from the correct line after `SplFileObject::seek()`
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-246723@lists.php.net to get a copy of this message
Issue: https://github.com/php/php-src/issues/13916 Author: MadeinDave ### Description I have a CSV file formatted like this: ```csv ID;DATE;SUPPLIER;STATUS;A1;A2 ;01/01/2024;1;OK;; ;01/01/2024;2;OK;; ``` The following code: ```php <?php $fileObj = new \SplFileObject("file.txt"); $fileObj->setFlags(\SplFileObject::READ_CSV | \SplFileObject::SKIP_EMPTY | \SplFileObject::READ_AHEAD | \SplFileObject::DROP_NEW_LINE ); $fileObj->setCsvControl(';'); $fileObj->seek(1); foreach ($fileObj as $row) { die(var_dump($row)); } ``` Resulted in this output: ``` array(6) { [0]=> string(2) "ID" [1]=> string(4) "DATE" [2]=> string(8) "SUPPLIER" [3]=> string(6) "STATUS" [4]=> string(17) "A1" [5]=> string(17) "A2" } ``` But I expected this output instead: ``` array(6) { [0]=> string(0) "" [1]=> string(10) "01/01/2024" [2]=> string(1) "1" [3]=> string(2) "OK" [4]=> string(0) "" [5]=> string(0) "" } ``` ### PHP Version PHP 8.0.27 && PHP 8.0.30 ### Operating System Ubuntu 22.04

« previous php.bugs (#246723) next »