php – feof() and an empty file


There is an empty file (0 bytes). Why doesn't feof() return true ?

    $f = fopen('file.dat', 'rb');
    echo feof($f);


(PHP 4, PHP 5, PHP 7)
feof — Проверяет, достигнут ли конец файла
bool feof ( resource $handle )

It's like a flag that reading is no longer possible. Have you tried reading at least once? And it's better to take if(filesize(…) > 0)

(PHP 4, PHP 5, PHP 7)
filesize — Возвращает размер файла
int filesize ( string $filename )
Scroll to Top