Re: problems looping through scandir return

From: Date: Tue, 05 May 2020 16:37:28 +0000
Subject: Re: problems looping through scandir return
References: 1 2 3 4  Groups: php.general 
Request: Send a blank email to php-general+get-327141@lists.php.net to get a copy of this message
It seems that warnings for count(false) are emitted starting with PHP 7.2, see https://3v4l.org/MuSbW By using foreach, you'll get warnings down to PHP 4.4, see https://3v4l.org/7eSZB Janis otrd., 2020. g. 5. maijs, plkst. 19:21 — lietotājs Jeffry Killen (< jekillen@prodigy.net>) rakstīja: > > > On May 5, 2020, at 4:09 AM, Jānis Elmeris <janis.elmeris@lv.lv> wrote: > > > > How do you access $_list items? > > foreach of false should > > emit a warning. count of false > > should > emit a warning as well. > > > > Janis > > I am using a for loop > > for($iter = 0; $itr< count($_list); $itr++) > > I haven't seen a warning. > > > > pirmd., 2020. g. 4. maijs, plkst. 01:45 — lietotājs Jeffry Killen (< > jekillen@prodigy.net>) rakstīja: > > Hello; > > > > I have encountered this issue before and solved it. > > But today it got me going around in circles again for > > several hours. > > > > The issue: > > > > $_list = []; > > if($_list = scandir( [valid directory] ) === false) > > { > > return // some error string; > > } > > > > Now there is code to loop through $_list > > It just keeps trying to loop and nothing in the array is processed > > > > It should have been > > if( ( $_list = scandir( [valid directory] ) ) === false) > > { > > return // some error string; > > } > > > > Now the loop sees a valid array in $_list and can process the > > $_list items > > > > So, is it possible that an error or warning could be issues for > > this type of situation?. The php interpreter seems to just be > > confused. > > > > I am used to having php poke its finger in my face when I > > got it wrong, syntax wise. > > > > Thanks for attention > > JK > >

« previous php.general (#327141) next »