Bug #67371 [Com]: fread does not return error (false) while reading out of file

From: Date: Mon, 02 Jun 2014 09:03:44 +0000
Subject: Bug #67371 [Com]: fread does not return error (false) while reading out of file
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-186007@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=67371&edit=1 ID: 67371 Comment by: roman4e at gmail dot com Reported by: roman4e at gmail dot com Summary: fread does not return error (false) while reading out of file Status: Not a bug Type: Bug Package: Filesystem function related Operating System: linux mint 15 PHP Version: 5.5.13 Block user comment: N Private report: N New Comment: There is one string in PHP manual for fread(): Reading stops as soon as one of the following conditions is met: - EOF (end of file) is reached So it SHOULD return false, when EOF is reached. Previous Comments: ------------------------------------------------------------------------ [2014-06-02 08:31:51] mike@php.net This is not a bug, reading past EOF is not an error case; read(2) states: "If the current file offset is at or past the end of file, no bytes are read, and read() returns zero." ------------------------------------------------------------------------ [2014-06-02 07:47:40] roman4e at gmail dot com Description: ------------ php v.5.5.5 (cli) (built: Mar 17 2014 12:31:03) (DEBUG) fread() does not return error (false) on read out of file, returns "" (empty string) Test script: --------------- $f = fopen("file","r"); // file must be several KBytes size $page = 0; while ( !fseek($f,$page,SEEK_SET) ) { $page += 1024; $str = fread($f,1024); if ( $str === false ) die("error reading block"); } echo "ok" Expected result: ---------------- fread should return false Actual result: -------------- file size of 76800 result of reading out of file. last parametr is type of data returned by fread Pageoff = 75776 fseek=0 ftell=75776 read=1024 string Pageoff = 76800 fseek=0 ftell=76800 read=0 string Pageoff = 77824 fseek=0 ftell=77824 read=0 string ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=67371&edit=1

« previous php.bugs (#186007) next »