[php-src] Issue #8851: SplFileObject calling fgets() after next() doesn't fetch the correct line

From: Date: Thu, 23 Jun 2022 14:03:19 +0000
Subject: [php-src] Issue #8851: SplFileObject calling fgets() after next() doesn't fetch the correct line
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-241792@lists.php.net to get a copy of this message
Issue: https://github.com/php/php-src/issues/8851 Author: Girgias ### Description The following code: ```php <?php $file = new SplTempFileObject(); // write to file for ($i = 0; $i < 5; $i++) { $file->fwrite("line {$i}" . PHP_EOL); } $file->rewind(); $file->next(); $file->next(); // read third line var_dump($file->fgets()); // where am I? echo $file->key(), ': ', $file->current(); ``` https://3v4l.org/W6GGD Resulted in this output: ``` string(7) "line 0 " 3: line 0 ``` But I expected (at least I think) this output instead: ``` string(7) "line 2 " 3: line 3 ``` ### PHP Version PHP 8.20 ### Operating System _No response_

« previous php.bugs (#241792) next »