#42175 [Opn]: feof() fails to detect the end of file
| From: | nikhil dot gupta at in dot ibm dot com | Date: | Thu, 02 Aug 2007 10:51:53 +0000 |
| Subject: | #42175 [Opn]: feof() fails to detect the end of file | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-115675@lists.php.net to get a copy of this message | ||
ID: 42175
User updated by: nikhil dot gupta at in dot ibm dot com
Reported By: nikhil dot gupta at in dot ibm dot com
Status: Open
Bug Type: Filesystem function related
Operating System: Linux, Win32-xp
PHP Version: 5CVS-2007-08-02 (snap)
New Comment:
I observed that when I use fgetcsv() to read a file to end, and then
check for EOF, feof() returns true. Hence I suspect the problem is with
fseek() that although it succceeds in taking the file pointer to EOF but
fails to set the EOF flag.
Previous Comments:
------------------------------------------------------------------------
[2007-08-02 10:23:45] nikhil dot gupta at in dot ibm dot com
Description:
------------
feof() is not able to detect the end of file even when the file pointer
is set to EOF using fseek() or any other ways. If we use the sample code
similar to that given in the help docs for feof() on php.net:
<?php
$fh = fopen("file.tmp", "w");
fclose($fh);
$fh = fopen("file.tmp", "r");
while(!feof()){
}
fclose($fh);
unlink("file.tmp");
?>
The code runs to endless loop as feof donot detect the EOF.
Reproduce code:
---------------
<?php
$fh = fopen("file.tmp", "w");
fwrite($fh, "aaa");
fclose($fh);
$fh = fopen("file.tmp", "r");
var_dump( ftell($fh) );
var_dump( fseek($fh, 0, SEEK_END) );
var_dump( ftell($fh) );
var_dump( feof($fh) );
fclose($fh);
unlink("file.tmp");
?>
Expected result:
----------------
int(0)
int(0)
int(3)
bool(true)
Actual result:
--------------
int(0)
int(0)
int(3)
bool(false)
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=42175&edit=1