note 48005 deleted from function.fread by danbrown

From: Date: Fri, 06 Jan 2012 21:12:15 +0000
Subject: note 48005 deleted from function.fread by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-185440@lists.php.net to get a copy of this message
Note Submitter: drane ---- 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.)

« previous php.notes (#185440) next »