|  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: 2016-07-01 16:06 UTC
From: kentaro at ranvis dot com Assigned:
Status: Verified Package: SPL related
PHP Version: 5.5.3 OS: *
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: kentaro at ranvis dot com
New email:
PHP Version: OS:


 [2013-09-01 10:09 UTC] kentaro at ranvis dot com
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");
assert('$f->current() === "line 1\n"');
assert('$f->current() === "line 2\n"');
var_dump($f->ftell()); // 14
assert('$f->current() === "line 3"');

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


Add a Patch

Pull Requests

Pull requests:

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2013-09-01 11:49 UTC]
-Status: Open +Status: Verified -Operating System: Windows +Operating System: *
 [2013-09-01 11:49 UTC]
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]

    $f = new SplFileObject('php://temp', 'w+');
    $f->fwrite("line 1\nline 2\nline 3");

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]
Forgot: see <>.
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Tue Jul 27 10:01:23 2021 UTC