php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #42228 feof() fails to detect the eof flag for a file with a newline only.
Submitted: 2007-08-07 05:40 UTC Modified: 2008-07-11 21:44 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:1 (100.0%)
From: nikhil dot gupta at in dot ibm dot com Assigned:
Status: Wont fix Package: Filesystem function related
PHP Version: 4CVS-2007-08-07 (CVS) OS: Linux, Win32-xp
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: nikhil dot gupta at in dot ibm dot com
New email:
PHP Version: OS:

 

 [2007-08-07 05:40 UTC] 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)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-02-11 14:38 UTC] 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
 [2008-07-11 21:44 UTC] jani@php.net
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.


 
PHP Copyright © 2001-2017 The PHP Group
All rights reserved.
Last updated: Sun Nov 19 01:31:42 2017 UTC