[php-src] Issue #8564: SplFileObject: next() moves to inexistent indexes

From: Date: Mon, 16 May 2022 04:13:07 +0000
Subject: [php-src] Issue #8564: SplFileObject: next() moves to inexistent indexes
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-241524@lists.php.net to get a copy of this message
Issue: https://github.com/php/php-src/issues/8564 Author: gabrielpl ### Description The following [code](https://3v4l.org/5dYAL): ```php <?php declare(strict_types=1); const LINES = 5; const INDEX = 10; $file = new SplFileObject('/tmp/test.txt', 'w+'); // write to files for ($i = 0; $i < LINES; $i++) { $file->fwrite("line {$i}" . PHP_EOL); } // behaviour of next() $file->rewind(); for ($i = 0; $i < INDEX; $file->next(), $i++); echo 'next(): ', $file->key(), PHP_EOL; // behaviour of seek() $file->rewind(); $file->seek(INDEX); echo 'seek(): ', $file->key(), PHP_EOL; ``` Resulted in this output: ``` next(): 10 seek(): 5 ``` But I expected this output instead: ``` next(): 5 seek(): 5 ``` ### PHP Version PHP 8.1.6 ### Operating System Windows 11

« previous php.bugs (#241524) next »