|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #27461 fread($fp,0) generates warning
Submitted: 2004-03-02 11:58 UTC Modified: 2004-03-02 13:46 UTC
From: mark at quarella dot co dot uk Assigned:
Status: Not a bug Package: Filesystem function related
PHP Version: 4.3.5RC3 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.
Block user comment
Status: Assign to:
Bug Type:
From: mark at quarella dot co dot uk
New email:
PHP Version: OS:


 [2004-03-02 11:58 UTC] mark at quarella dot co dot uk
fread($handle, 0) generates a warning where it did not in earlier versions.

This typically occurs in situations where the filesize is calculated:
  fread($handle, filesize($filename));

(where $handle is the result of opening file $filename, and $filename is the name of a zero-byte file)

Reproduce code:
// Taken from fread documentation, will generate WARNING
// if something.txt exists and is empty (0 bytes)

// get contents of a file into a string
$filename = "/usr/local/something.txt";
$handle = fopen($filename, "r");
$contents = fread($handle, filesize($filename));

Expected result:
Would expect $contents == '', no errors or warnings

Actual result:
Warning: fread(): Length parameter must be greater than 0. in xx on line yy


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2004-03-02 12:39 UTC]
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at and the instructions on how to report
a bug at

This was a deliberate change.
 [2004-03-02 13:46 UTC] mark at quarella dot co dot uk
Sorry to be dumb but I can't find reference to the change in ChangeLog, NEWS, at - where should I be looking?

(A Google for the text of the Warning message just shows up several sites running PHP which I guess have been broken by this change.)
 [2004-03-31 05:18 UTC] miki_rosanda at yahoo dot com
we had the same problem

try to add:
$handle = fopen($filename, "rb, r");

or use file_get_contents()

PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Sun Jun 20 02:01:23 2021 UTC