php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #75917 SplFileObject::seek broken with CSV flags
Submitted: 2018-02-05 09:40 UTC Modified: 2018-02-05 13:59 UTC
From: nyamsprod at gmail dot com Assigned:
Status: Closed Package: SPL related
PHP Version: Next Minor Version OS: Irrelevant
Private report: No CVE-ID: None
 [2018-02-05 09:40 UTC] nyamsprod at gmail dot com
Description:
------------
Prior to PHP7.2.0 SplFileObject::seek would return false if the seeked line did not exists. Since PHP7.2.0 it returns the last line of the file instead.

see https://3v4l.org/pl0Kg

Test script:
---------------
<?php

$expected = [
    ['john', 'doe', 'john.doe@example.com', '0123456789'],
    ['jane', 'doe', 'jane.doe@example.com'],
];

$tmp = new SplTempFileObject();
foreach ($expected as $row) {
    $tmp->fputcsv($row);
}
$tmp->setFlags(0);
$tmp->seek(23);
var_dump($tmp->current()); //expected false
$tmp->setFlags(SplFileObject::READ_CSV | SplFileObject::SKIP_EMPTY);
$tmp->seek(23);
var_dump($tmp->current());  //expected false (get the last row instead)


Patches

Add a Patch

Pull Requests

Pull requests:

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-02-05 13:59 UTC] cmb@php.net
According to `git bisect` the relevant commit is
<http://git.php.net/?p=php-src.git;a=commit;h=0a45e8f096a04464bda6277c6f3d0b5461737a27>
 [2021-12-06 17:42 UTC] cmb@php.net
The following pull request has been associated:

Patch Name: Fix #75917: SplFileObject::seek broken with CSV flags.
On GitHub:  https://github.com/php/php-src/pull/7697
Patch:      https://github.com/php/php-src/pull/7697.patch
 [2021-12-06 18:05 UTC] git@php.net
Automatic comment on behalf of Flashwade1990 (author) and cmb69 (committer)
Revision: https://github.com/php/php-src/commit/daf79e2d91dc4dd47f516229ebc5922ad35f27ab
Log: Fix #75917: SplFileObject::seek broken with CSV flags
 [2021-12-06 18:05 UTC] git@php.net
-Status: Open +Status: Closed
 
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Wed May 25 01:05:44 2022 UTC