php-src icon indicating copy to clipboard operation
php-src copied to clipboard

SplFileObject method seek doesn't work as expected

Open ASiRoS opened this issue 4 years ago • 4 comments

Description

The following code:

<?php
$splFileObject = new SplFileObject('any.csv');
$splFileObject->setFlags(
    SplFileObject::READ_CSV
    | SplFileObject::READ_AHEAD
    | SplFileObject::SKIP_EMPTY
    | SplFileObject::DROP_NEW_LINE
);

$splFileObject->seek(0);

$splFileObject->key(); // 0 Returns as expected

$splFileObject->seek(1);
$splFileObject->key(); // 1 Returns as expected

$splFileObject->seek(2);
$splFileObject->key(); // 1 But if we give anything more than 1, it will return 1

Resulted in this output:

Seek doesn't get you to the expected line, but instead gets you to the second one (1).

But I expected this output instead:

Seek will move to the expected lines that exists.

seek works fine for PHP 7.4 and PHP 8.1, but results in this error for PHP 8.0

PHP Version

PHP 8.0.16

Operating System

Ubuntu 20.04

ASiRoS avatar Mar 29 '22 12:03 ASiRoS

I cannot reproduce with PHP 8.0.17-dev. This is likely a duplicate of #8121.

cmb69 avatar Mar 29 '22 13:03 cmb69

Thank you, I will test it tomorrow using PHP 8.0.17

ASiRoS avatar Mar 29 '22 13:03 ASiRoS

Sorry, couldn't test it yesterday, so writing it today. Tried testing it with current available PHP 8.0.17, but unfortunately didn't help, I think the next patch version will include the fix, as the latest one you tested was dev version, right?

ASiRoS avatar Mar 31 '22 09:03 ASiRoS

Oh, right, the fix should be in 8.0.18RC1.

cmb69 avatar Mar 31 '22 10:03 cmb69