|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #27508 feof() broken for user-defined streams
Submitted: 2004-03-05 16:05 UTC Modified: 2005-08-18 16:32 UTC
Avg. Score:4.6 ± 0.7
Reproduced:10 of 11 (90.9%)
Same Version:4 (40.0%)
Same OS:7 (70.0%)
From: adam at trachtenberg dot com Assigned: wez (profile)
Status: Closed Package: Network related
PHP Version: 5CVS-2005-03-24 OS: *
Private report: No CVE-ID: None
 [2004-03-05 16:05 UTC] adam at trachtenberg dot com
It looks like feof() doesn't work correctly in all cases 
for user-defined streams. It seems like the class 
stream_eof() method is not being called when feof() is 
invoked in PHP.

This works correctly using 4.3.5RC3, but not PHP 5 
current CVS. It also works correctly if I do an 
fpassthru() on the file pointer and let PHP handle the 
feof() check.

Reproduce code:
See VariableStream class in the manual:

In particular the while(!feof()) bit.

Expected result:
string(18) "line1

(This is what I get from PHP 4.3.5RC3)

Actual result:
string(18) "line1


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2004-03-09 08:47 UTC]
Wez, the fix didn't quite fix it.

Adam, can you please come up with a test case and send it to internals@ ? (The one in manual is a bit long, could it be made any shorter?)

 [2004-03-09 11:31 UTC] adam at trachtenberg dot com
Here's an example where the class is just a wrapper 
around fopen(), fread(), fwrite(), etc.

It's at

In PHP 4, you get:


PHP 5 outputs no data.
 [2004-03-09 11:32 UTC] adam at trachtenberg dot com
Oops. Wrong file extension. Should be:
 [2005-05-11 04:02 UTC]
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
Thank you for the report, and for helping us make PHP better.

Fixed in HEAD.
 [2005-08-18 16:32 UTC]
This bug will actually not be fixed in 5.0.x but instead will only be fixed in 5.1.x and above.

Please use version_compare() to handle this problem.
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Thu Mar 30 21:03:39 2023 UTC