Bug #65601 [Asn->Opn]: SplFileObject->valid() should not return false when it reached EOF

From: Date: Tue, 24 Oct 2017 07:25:21 +0000
Subject: Bug #65601 [Asn->Opn]: SplFileObject->valid() should not return false when it reached EOF
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-212062@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: kalle@php.net Reported by: kentaro at ranvis dot com Summary: SplFileObject->valid() should not return false when it reached EOF -Status: Assigned +Status: Open Type: Bug Package: SPL related Operating System: * PHP Version: 5.5.3 -Assigned To: colder +Assigned To: Block user comment: N Private report: N Previous Comments: ------------------------------------------------------------------------ [2014-02-27 03:44:37] 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. ------------------------------------------------------------------------ [2013-09-01 11:49:58] 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-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

« previous php.bugs (#212062) next »