php.net |  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
 [2004-03-02 11:58 UTC] mark at quarella dot co dot uk
Description:
------------
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));
fclose($handle);


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


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

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

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 php.net/fread - 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()

regards,
miki
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Thu Nov 26 12:01:23 2020 UTC