#42228 [Opn->WFx]: feof() fails to detect the eof flag for a file with a newline only.

From: Date: Fri, 11 Jul 2008 21:44:24 +0000
Subject: #42228 [Opn->WFx]: feof() fails to detect the eof flag for a file with a newline only.
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-126556@lists.php.net to get a copy of this message
ID: 42228 Updated by: jani@php.net Reported By: nikhil dot gupta at in dot ibm dot com -Status: Open +Status: Wont fix Bug Type: Filesystem function related Operating System: Linux, Win32-xp PHP Version: 4CVS-2007-08-07 (CVS) New Comment: We are sorry, but we can not support PHP 4 related problems anymore. Momentum is gathering for PHP 6, and we think supporting PHP 4 will lead to a waste of resources which we want to put into getting PHP 6 ready. Previous Comments: ------------------------------------------------------------------------ [2008-02-11 14:38:34] sb1304 at hotmail dot com <?php $fp = fopen("file2.tmp", "w"); $csv_string = "\n"; fwrite($fp, $csv_string); fclose($fp); $fp = fopen("file2.tmp", "r"); var_dump( ftell($fp) ); var_dump( fgetcsv($fp) ); var_dump( ftell($fp) ); var_dump( feof($fp) ); var_dump( fseek($fp, 0, SEEK_END) ); var_dump( ftell($fp) ); var_dump( fgetc($fp) ); var_dump( feof($fp) ); fclose($fp); ?> Gives: int(0) array(1) { [0]=> string(0) "" } int(1) bool(false) int(0) int(1) bool(false) bool(true) And a feof of true. Same result as in 42175? S ------------------------------------------------------------------------ [2007-08-07 05:40:24] nikhil dot gupta at in dot ibm dot com Description: ------------ feof() is failing to detect the end of file for a file containing a blank file ("\n" character only). This behaviour is seen on php5 and php6 both. Reproduce code: --------------- <?php $fp = fopen("file2.tmp", "w"); $csv_string = "\n"; fwrite($fp, $csv_string); fclose($fp); $fp = fopen("file2.tmp", "r"); var_dump( ftell($fp) ); var_dump( fgetcsv($fp) ); var_dump( ftell($fp) ); var_dump( feof($fp) ); var_dump( fseek($fp, 0, SEEK_END) ); var_dump( ftell($fp) ); var_dump( feof($fp) ); fclose($fp); ?> Expected result: ---------------- int(0) array(1) { [0]=> string(0) "" } int(1) bool(true) int(0) int(1) bool(true) Actual result: -------------- int(0) array(1) { [0]=> string(0) "" } int(1) bool(false) int(0) int(1) bool(false) ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=42228&edit=1

« previous php.bugs (#126556) next »