\SplFileObject->seek() behaviour has changed (between 8.0.13 - 8.0.16 and 8.1.0-8.1.3)
Description
The following code with a 3 line csv file:
<?php
$file = new \SplFileObject('/local/file/path.csv', 'r');
$file->setFlags(\SplFileObject::READ_CSV);
$file->seek(PHP_INT_MAX);
$count = $file->key();
print "COUNT OF LINES (seek) : {$count}\n";
$file->rewind();
while ($file->valid()) {
$file->fgets();
}
print "COUNT OF LINES (while) : {$file->key()}\n";
Resulted in this output on php 8.0.16 and 8.1.3:
COUNT OF LINES (seek) : 0
COUNT OF LINES (while) : 4
But I expected this output instead - this is the output I got on PHP <8.1.2 and PHP < 8.0.16:
COUNT OF LINES (seek) : 4
COUNT OF LINES (while) : 4
8.1.x:
https://3v4l.org/JXeQq#v8.1.1 - Working https://3v4l.org/JXeQq#v8.1.2 - Not Working
8.0.x:
https://3v4l.org/JXeQq#v8.0.14 - Working https://3v4l.org/JXeQq#v8.0.15 - Not Working
Using $file->seek(PHP_INT_MAX) is the most given answer for how to count the number of lines in a CSV in stack overflow, so it is very concerning that this is now broken.
PHP Version
PHP 8.1.3 and PHP 8.0.16
Operating System
Ubuntu 20.04
I'm no expert but I think it might have been introduced here: https://bugs.php.net/bug.php?id=75917
This looks like a duplicate of #8121, which will be fixed as of PHP 8.0.18 and 8.1.5, respectively.
@cmb69 is there any update on when 8.0.18 will be released? I'm concerned because 8.0.17 isn't released yet and its been two months since 8.0.16. Waiting 4 months for a fix this critical seems unreasonable.
PHP 8.0.17 has been released 4 weeks ago; maybe an announcement was missing? Anyhow, PHP 8.0.18 is supposed to be released today.
Ah! Ok, I just noticed that this page https://www.php.net/releases/index.php only lists the unsupported releases; so it's always one behind.
Thanks for getting back to me so quick.