Re: Re: Newbie: Question about filesize()

From: Date: Thu, 07 Feb 2002 00:04:46 +0000
Subject: Re: Re: Newbie: Question about filesize()
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-83787@lists.php.net to get a copy of this message
On Wed, 2002-02-06 at 15:33, Jeff Sheltren wrote: > At 10:27 AM 2/6/2002 -0500, Ben Crawford wrote: > >You also seem to have an extra equals. Your loop should read: > > > >while (false != ($file=readdir($handle))){ > > I think you could eliminate the "false !=" in the while condition... > > It should be just the same if you write > while (($file = readdir($handle))) > > right? > > -Jeff Wrong, actually. If you have any files in that directory which have names which would evaluate as false in PHP, then your way will fail on them and you'll get a truncated directory listing. Do 'touch 0' in a directory and give it a shot; you'll see what I mean. However, the original example does the same thing, since it only checks whether the result of the readdir() evaluates to FALSE, not whether it actually is a boolean FALSE value. The correct way to do this is: while (FALSE !== ($file = readdir($handle))) { . . . } Note the !== instead of !=. Hope this helps, Torben -- Torben Wilson <torben@php.net> http://www.thebuttlesschaps.com http://www.hybrid17.com http://www.inflatableeye.com +1.604.709.0506

« previous php.general (#83787) next »