-
Notifications
You must be signed in to change notification settings - Fork 7.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SplFileObject - Inconsistent behavior of seek and key with csv file #8121
Labels
Comments
cmb69
added a commit
to cmb69/php-src
that referenced
this issue
Feb 22, 2022
First, we must not free the current line before we call `spl_filesystem_file_read_csv()`, because then the `current_line` will not be properly updated. Since the EOF check is superfluous here, we move that part of the code to the branch for subtypes. This issue has been introduced by the fix for bug 75917. Second, we only must increase the `current_line` if we're not reading ahead. This issue has been introduced by the fix for bug 62004.
cmb69
added a commit
to cmb69/php-src
that referenced
this issue
Feb 24, 2022
First, we must not free the current line before we call `spl_filesystem_file_read_csv()`, because then the `current_line` will not be properly updated. Since the EOF check is superfluous here, we move that part of the code to the branch for subtypes. This issue has been introduced by the fix for bug 75917. Second, we only must increase the `current_line` if we're not reading ahead. This issue has been introduced by the fix for bug 62004.
cmb69
added a commit
that referenced
this issue
Mar 8, 2022
* PHP-8.0: Fix GH-8121: SplFileObject - seek and key with csv file inconsistent
cmb69
added a commit
that referenced
this issue
Mar 8, 2022
* PHP-8.1: Fix GH-8121: SplFileObject - seek and key with csv file inconsistent
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Description
In the code below, I'm opening a csv file, seeking to each line and trying to get the contents.
$file->current()
returns the correct line everytime but$file->key()
returns 0 and then 1 for each line. This only happens when withREAD_AHEAD
andREAD_CSV
flags are used.Note that
o()
is just a wrapper forecho
andprint_r
.The following code:
Resulted in this output:
But I expected this output instead:
If I remove
READ_CSV
flag, the line numbers I get areFinally, If I remove
READ_AHEAD
as well, I get the expected output.Looping through
When not using seek, everything works fine.
Outputs
I am attaching the csv file I used as well.
import2.csv
PHP Version
PHP 8.1.2
Operating System
Windows 11, Xampp 3.3.0
The text was updated successfully, but these errors were encountered: