php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #65600 SplFileObject->next() not move next without current()
Submitted: 2013-09-01 10:09 UTC Modified: 2022-05-16 11:51 UTC
From: kentaro at ranvis dot com Assigned: cmb (profile)
Status: Duplicate Package: SPL related
PHP Version: 5.5.3 OS: *
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: kentaro at ranvis dot com
New email:
PHP Version: OS:

 

 [2013-09-01 10:09 UTC] kentaro at ranvis dot com
Description:
------------
SplFileObject->next() doesn't move to the next line unless ->current() is called in advance.


Test script:
---------------
$f = new SplFileObject('php://memory', 'r+');

$f->fwrite("line 1\nline 2\nline 3");
$f->rewind();
assert('$f->current() === "line 1\n"');
$f->next();
assert('$f->current() === "line 2\n"');
$f->next();
var_dump($f->ftell()); // 14
assert('$f->current() === "line 3"');

$f->rewind();
$f->next();
$f->next();
var_dump($f->ftell()); // 0
assert('$f->current() === "line 3"'); // fails


Patches

Pull Requests

Pull requests:

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-09-01 11:49 UTC] requinix@php.net
-Status: Open +Status: Verified -Operating System: Windows +Operating System: *
 [2013-09-01 11:49 UTC] requinix@php.net
Using the READ_AHEAD flag will enable the behavior you're expecting. I don't know 
if that requirement is intentional or necessary.
 [2013-09-01 14:46 UTC] kentaro at ranvis dot com
Thank you. It worked as expected with setFlags(SplFileObject::READ_AHEAD) before rewind().
I'll wait for further comment to see if this is a requirement (it seems to be.)
 [2016-07-01 15:48 UTC] cmb@php.net
Consider:

    <?php
    $f = new SplFileObject('php://temp', 'w+');
    $f->fwrite("line 1\nline 2\nline 3");
    $f->rewind();
    $f->next();
    $f->next();
    $f->next();
    var_dump($f->key());
    var_dump($f->current());

While key() says we're at line 3, current() returns the first
line. That doesn't make sense; either key() should return 1, or
current() should return the third line.
 [2016-07-01 16:06 UTC] cmb@php.net
Forgot: see <https://3v4l.org/qM88J>.
 [2022-05-16 11:51 UTC] cmb@php.net
-Status: Verified +Status: Duplicate -Assigned To: +Assigned To: cmb
 [2022-05-16 11:51 UTC] cmb@php.net
I'm closing this in favor of <https://github.com/php/php-src/issues/8562>.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 23:01:29 2024 UTC