|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #28621 fgets calls always return false if end-of-file has occured earlier
Submitted: 2004-06-03 12:02 UTC Modified: 2004-06-04 15:50 UTC
From: pickett at sumu dot org Assigned:
Status: Not a bug Package: Filesystem function related
PHP Version: 4.3.7RC1 OS:
Private report: No CVE-ID: None
 [2004-06-03 12:02 UTC] pickett at sumu dot org
fgets calls will keep returning false if a fd has at some point reached end-of-file, even though the pointer is no longer at EOF.  feof() will also keep returning true.

Using fread() instead of fgets() works, but is inconvenient if you'd like to read just one line at a time.

Reproduce code:
  $fdw = fopen("test", "w");
  $fdr = fopen("test", "r");

  fputs($fdw, "testing 1..\n");
  var_dump(fgets($fdr, 0xff));
  var_dump(fgets($fdr, 0xff));
  fputs($fdw, "testing 2..\n");
  var_dump(fgets($fdr, 0xff));

Expected result:
string(12) "testing 1..
string(12) "testing 2..

Actual result:
string(12) "testing 1..


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2004-06-04 15:50 UTC]
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at and the instructions on how to report
a bug at

This is to be expected. 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Sat Jan 23 23:01:26 2021 UTC