php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #65603 feof not reporting end of file when using fread
Submitted: 2013-09-02 03:58 UTC Modified: 2013-09-02 04:55 UTC
From: grom358 at gmail dot com Assigned:
Status: Not a bug Package: *General Issues
PHP Version: 5.5.3 OS: Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
39 + 38 = ?
Subscribe to this entry?

 
 [2013-09-02 03:58 UTC] grom358 at gmail dot com
Description:
------------
If using fread and have read the last byte in the file, feof still reports have 
not reached end of file.

Test script:
---------------
<?php
$fp = fopen('feof.bin', 'w');
fwrite($fp, 'abc');
fclose($fp);

$fp = fopen('feof.bin', 'r');
$bytes = fread($fp, 3);
echo feof($fp) ? 't' : 'f';
echo PHP_EOL;
fclose($fp);

unlink('feof.bin');

Expected result:
----------------
Expected feof to return true

Actual result:
--------------
feof returned false. 

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-09-02 04:55 UTC] rasmus@php.net
-Status: Open +Status: Not a bug
 [2013-09-02 04:55 UTC] rasmus@php.net
feof() indicates that you have tried to read beyond the end of the file. For a 3-
byte file, if you only read 3 bytes you have not yet tried to read beyond the end 
of the file and thus feof() has not triggered yet. feof() cannot predict that the 
next read will fail. By the time you do the next read perhaps the file has grown. 
This is exactly how this function works in C as well which is where it comes 
from.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Jun 11 03:01:29 2024 UTC