Re: Odd result from readdir()

From: Date: Thu, 18 Jan 2024 15:19:39 +0000
Subject: Re: Odd result from readdir()
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-328358@lists.php.net to get a copy of this message
Thank you to both Yang and Peter; the problem is, as you suggested, in the line: while ($filename = (readdir($dh) !== false)) and it now works correctly. I knew I was having a case of the stupids but couldn't find it. Also, thank you Jeffery. I was aware of scandir() and this was sort of a random choice but when it didn't work it refocused my mind onto the question of "why not" instead of a workaround. Surprising how easily we can fall down the wrong rabbit hole! Thanks again fellows for the prompt replies. John ====== On Thu, 2024-01-18 at 10:12 +0000, Peter Ford wrote: > I think you problem is in this line, specifically where the brackets are:  > > while ($filename = (readdir($dh) !== false)) > > That is setting $filename to the value of the expression (readdir($dh) !== false), > which is ’true’ or 1 > > I think you wanted  > > while (($filename = readdir($dh)) !== false)) > > Cheers > > Pete > > On 18 Jan 2024, at 06:08, John <john.iliffe@iliffe.ca> wrote: > > > > while ($filename = (readdir($dh) !== false)) >

« previous php.general (#328358) next »