3v4l.org

run code in 500+ PHP versions simultaneously
<?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;
Output for 7.4.0 - 7.4.33, 8.0.1 - 8.0.30, 8.1.0 - 8.1.34, 8.2.0 - 8.2.30, 8.3.0 - 8.3.30, 8.4.1 - 8.4.18, 8.5.0 - 8.5.3
next(): 10 seek(): 5

preferences:
76.37 ms | 1248 KiB | 4 Q