Edit report at https://bugs.php.net/bug.php?id=65603&edit=1

 ID:                 65603
 Updated by:         ras...@php.net
 Reported by:        grom358 at gmail dot com
 Summary:            feof not reporting end of file when using fread
-Status:             Open
+Status:             Not a bug
 Type:               Bug
 Package:            *General Issues
 Operating System:   Linux
 PHP Version:        5.5.3
 Block user comment: N
 Private report:     N

 New Comment:

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.


Previous Comments:
------------------------------------------------------------------------
[2013-09-02 03:58:57] 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. 


------------------------------------------------------------------------



-- 
Edit this bug report at https://bugs.php.net/bug.php?id=65603&edit=1

Reply via email to