php.net |  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
Votes:1
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
Have you experienced this issue?
Rate the importance of this bug to you:

 [2013-09-01 10:15 UTC] kentaro at ranvis dot com
Description:
------------
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");
$f->rewind();
assert('$f->valid() === true');
assert('$f->eof() === false');
assert('$f->current() === "line 1"');
assert('$f->valid() === true'); // fails
assert('$f->eof() === true');



Patches

Add a Patch

Pull Requests

Add a Pull Request

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
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] felipe@php.net
-Status: Verified +Status: Assigned -Assigned To: +Assigned To: colder
 [2014-02-27 03:44 UTC] levim@php.net
In this case you never call `next()`, so I am quite surprised this happens. As mentioned by rquinix@php.net, it may be related to bug #65600.
 [2017-10-24 07:25 UTC] kalle@php.net
-Status: Assigned +Status: Open -Assigned To: colder +Assigned To:
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Wed Dec 11 08:01:24 2019 UTC