Edit report at https://bugs.php.net/bug.php?id=65601&edit=1

 ID:                 65601
 Updated by:         fel...@php.net
 Reported by:        kentaro at ranvis dot com
 Summary:            SplFileObject->valid() should not return false when
                     it reached EOF
-Status:             Verified
+Status:             Assigned
 Type:               Bug
 Package:            SPL related
 Operating System:   *
 PHP Version:        5.5.3
-Assigned To:        
+Assigned To:        colder
 Block user comment: N
 Private report:     N



Previous Comments:
------------------------------------------------------------------------
[2013-09-01 11:49:58] requi...@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-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

Reply via email to