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: Open Package: SPL related
PHP Version: Next Minor Version OS: Irrelevant
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [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

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>
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Thu Oct 01 05:01:24 2020 UTC