Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 1.8.3

Bug #4236 fread PHP warning on zero length read
Submitted: 2005-04-27 17:59 UTC
From: rick dot overman at gmail dot com Assigned: fab
Status: Closed Package: Cache_Lite
PHP Version: 4.3.10 OS: Linux
Roadmaps: (Not assigned)    
Subscription  


 [2005-04-27 17:59 UTC] rick dot overman at gmail dot com
Description: ------------ In Lite.php line 638 $data = @fread($fp, $length); Comment from http://www.php.net/fread ------------------------------------- Somewhere between 4.2.3 and 4.3.9, the behaviour of fread() was changed slightly. When you ask to fread() 0 bytes of data, it spits out a warning (IMO for no good reason. I think reading 0 bytes is perfectly valid, if not very useful.) Consequently, to write warning-free code using fread, you'd have to take code like this: $content=fread($fd,filesize($myfile)); and replace it with this: $content=''; $length=filesize($myfile); if($length) { $content = fread($fd, $length); } ...or this, depending on your taste: $length=filesize($myfile); if($length) { $content = fread($fd, $length); } else { $content=''; } Reproduce code: --------------- Read an empty cache. Expected result: ---------------- No PHP warning if cache empty. Actual result: -------------- Produces a PHP Warning.

Comments

 [2005-05-14 09:37 UTC] fab
This bug has been fixed in CVS. In case this was a documentation problem, the fix will show up at the end of next Sunday (CET) on pear.php.net. In case this was a pear.php.net website problem, the change will show up on the website in short time. Thank you for the report, and for helping us make PEAR better.