Bug #68466 [Com]: Iterating SplFileObject shows empty line at end of file

From: Date: Sat, 22 Nov 2014 22:44:55 +0000
Subject: Bug #68466 [Com]: Iterating SplFileObject shows empty line at end of file
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-188745@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=68466&edit=1 ID: 68466 Comment by: fmargaine@php.net Reported by: tim_siebels_aurich at yahoo dot de Summary: Iterating SplFileObject shows empty line at end of file Status: Open Type: Bug Package: SPL related PHP Version: 5.6.3 Block user comment: N Private report: N New Comment: Hi, This is the equivalent you're looking for: <?php $o = new SplFileObject(__FILE__); while (!$o->eof()) { var_dump($o->fgets()); } ?> However, it *is* weird that the iterator doesn't stop at the end of file. Previous Comments: ------------------------------------------------------------------------ [2014-11-20 20:48:44] tim_siebels_aurich at yahoo dot de Description: ------------ Iterating over a SplFileObject differs from using fopen() and friends. SplFileObject is supposed to be an object oriented interface for the file handling functions. Their output shouldn't be different. Test script: --------------- <?php $o = new SplFileObject(__FILE__); foreach($o as $key=>$val) { var_dump($val); } /* Should be the same as $h = fopen(__FILE__, 'r'); while(!feof($h)) { var_dump(fgets($h)); } */ Expected result: ---------------- string(3) "<? " string(34) "$o = new SplFileObject(__FILE__); " string(1) " " string(28) "foreach($o as $key=>$val) { " string(18) " var_dump($val); " string(2) "} " bool(false) Actual result: -------------- <?php $o = new SplFileObject(__FILE__); foreach($o as $key=>$val) { var_dump($val); } ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=68466&edit=1

« previous php.bugs (#188745) next »