Bug #65601 [Opn->Ver]: SplFileObject->valid() should not return false when it reached EOF
| From: | requinix@php.net | Date: | Sun, 01 Sep 2013 11:49:58 +0000 |
| Subject: | Bug #65601 [Opn->Ver]: SplFileObject->valid() should not return false when it reached EOF | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-181388@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=65601&edit=1
ID: 65601
Updated by: requinix@php.net
Reported by: kentaro at ranvis dot com
Summary: SplFileObject->valid() should not return false when
it reached EOF
-Status: Open
+Status: Verified
Type: Bug
Package: SPL related
-Operating System: Windows
+Operating System: *
PHP Version: 5.5.3
Block user comment: N
Private report: N
New Comment:
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.
Previous Comments:
------------------------------------------------------------------------
[2013-09-01 10:15:20] 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');
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=65601&edit=1