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
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: grom358 at gmail dot com
New email:
PHP Version: OS:

 

 [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: Wed May 15 21:01:30 2024 UTC