Notice that the behavior of fgets after a seek changed on PHP 8.0.10, if you seek to line 50 and run fgets, it will give you line 50, while on PHP 5.1~8.0.0 it would give you line 51:
<?php
$file = new SplTempFileObject();
for ($i = 0; $i < 100; $i++) {
$file->fwrite("Foo $i\n");
}
$file->seek(50);
echo json_encode(array(
array('line' => $file->key(), 'contents' => trim($file->fgets())),
array('line' => $file->key(), 'contents' => trim($file->fgets())),
array('line' => $file->key(), 'contents' => trim($file->fgets())),
), JSON_PRETTY_PRINT);
?>
Results:
PHP 8.0.1+
[
{
"line": 50,
"contents": "Foo 50"
},
{
"line": 50,
"contents": "Foo 51"
},
{
"line": 51,
"contents": "Foo 52"
}
]
PHP 5.1 to 8.0.0
[
{
"line": 50,
"contents": "Foo 51"
},
{
"line": 51,
"contents": "Foo 52"
},
{
"line": 52,
"contents": "Foo 53"
}
]