php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #21877 fread may read less bytes than requested even if EOF is not reached ...
Submitted: 2003-01-25 12:56 UTC Modified: 2003-06-08 09:35 UTC
Votes:3
Avg. Score:4.3 ± 0.9
Reproduced:2 of 2 (100.0%)
Same Version:1 (50.0%)
Same OS:1 (50.0%)
From: hholzgra@php.net Assigned:
Status: Closed Package: Documentation problem
PHP Version: 4CVS-2003-01-25 (stable) OS: *
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: hholzgra@php.net
New email:
PHP Version: OS:

 

 [2003-01-25 12:56 UTC] hholzgra@php.net
i asume this not only true for C fread() but also for PHP ?

if so -> should be documented as such ...

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-01-25 13:07 UTC] hholzgra@php.net
ok, it only true for non-blocking php streams ...

but still this should be mentioned on the fread() page
 [2003-01-27 19:53 UTC] gaelx at free dot fr
here was my code:

$f=fopen("./foo","r"); 
while($c=fgetc($f)){
 ...
  }

...and the 'while' loop was quit long before EOF was reached.
After examination, it was quit when a character 0 was read
(thus confusion between 0 and EOF.......)
 [2003-01-27 20:29 UTC] philip@php.net
Try this code instead:

$f = fopen("./foo","r");
while (false !== ($c = fgetc($f))) {
    ...
}

As this is really what you want to do ;)  The documentation for fgetc() really needs to mention this as most others that might encounter this 0==false do (such as readdir).

A documention problem is to do the following to the fgetc docs:

a) Add an example that keeps in mind false vs 0
b) Implement the &return.falseproblem; entity.
 [2003-01-28 04:11 UTC] hholzgra@php.net
i prefere the 

while(!feof($f)) {
  $c=fgetc($f);
  ...
}

style ...
 [2003-01-28 13:07 UTC] philip@php.net
True.  How about using feof() in the example and including the falseproblem entity in the docs.
 [2003-06-08 09:01 UTC] nkist at operamail dot com
I have problems with below code too... It stops to read in the middle even for 10 KB files.

$fd= fread(fopen("http://something.com/index.php", "r"), 100000000000); if (!($fd)) {echo "Error in loading page. Please try again later.";}

$orgfile=Substr($fd,0, 100000000000);   echo $orgfile;   die;
 [2003-06-08 09:35 UTC] philip@php.net
That's unrelated, read the fread() docs for why.

This bug is now closed and will show up in the next manual build, thanks for the report :)  I chose not to use feof() as to more clearly demonstrate the 'false problem' and because it just means an extra function call for every character.

http://cvs.php.net/cvs.php/phpdoc/en/reference/filesystem/functions/fgetc.xml

 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sat Apr 19 02:01:26 2025 UTC