note 48005 added to function.fread

From: Date: Wed, 08 Dec 2004 21:53:03 +0000
Subject: note 48005 added to function.fread
Groups: php.notes 
Request: Send a blank email to php-notes+get-81548@lists.php.net to get a copy of this message
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=''; } (I'm aware that there are much better ways to read in a whole file at once. I'm just fixing up someone else's code after a server switch and ran across this stupid warning.) ---- Manual Page -- http://www.php.net/manual/en/function.fread.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+48005 Delete -- http://master.php.net/manage/user-notes.php?action=delete+48005&report=yes Reason: bad code -- http://master.php.net/manage/user-notes.php?action=delete+48005&report=yes&reason=bad+code Reason: spam -- http://master.php.net/manage/user-notes.php?action=delete+48005&report=yes&reason=spam Reason: useless example -- http://master.php.net/manage/user-notes.php?action=delete+48005&report=yes&reason=useless+example Reason: contains commercial links -- http://master.php.net/manage/user-notes.php?action=delete+48005&report=yes&reason=contains+commercial+links Reason: useless note -- http://master.php.net/manage/user-notes.php?action=delete+48005&report=yes&reason=useless+note Reject -- http://master.php.net/manage/user-notes.php?action=reject+48005&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#81548) next »