|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #65601 SplFileObject->valid() should not return false when it reached EOF
Submitted: 2013-09-01 10:15 UTC Modified: 2017-10-24 07:25 UTC
Avg. Score:3.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: kentaro at ranvis dot com Assigned:
Status: Open 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:15 UTC] kentaro at ranvis dot com
PHP document says that SplFileObject->valid() checks if a file pointer is not at EOF, just like SplFileObject->eof().
But since SplFileObject implements Iterator, valid() should not return false while the current element is valid.

Test script:
$f = new SplFileObject('php://memory', 'r+');
assert('$f instanceof Iterator');
$f->fwrite("line 1");
assert('$f->valid() === true');
assert('$f->eof() === false');
assert('$f->current() === "line 1"');
assert('$f->valid() === true'); // fails
assert('$f->eof() === true');


Add a Patch

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]
Related to bug #65600.

The first eof() assertion should be === true as rewind() would have rewound the 
stream and, to maintain normal iteration behavior, read the first line.

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-08 13:12 UTC]
-Status: Verified +Status: Assigned -Assigned To: +Assigned To: colder
 [2014-02-27 03:44 UTC]
In this case you never call `next()`, so I am quite surprised this happens. As mentioned by, it may be related to bug #65600.
 [2017-10-24 07:25 UTC]
-Status: Assigned +Status: Open -Assigned To: colder +Assigned To:
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun May 26 06:01:31 2024 UTC