Re: problems looping through scandir return

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> On May 5, 2020, at 9:40 AM, Christoph M. Becker <cmbecker69@xxxxxx> wrote:
> 
> On 05.05.2020 at 18:21, Jeffry Killen wrote:
>> 
>>> On May 5, 2020, at 4:09 AM, Jānis Elmeris <janis.elmeris@xxxxx> 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.
> 
> As of PHP 7.2.0, a warning is generated if anything but an array or
> object is passed to count().  Do you have proper error_reporting and
> friends set up?
> 
> Christoph

I believe the error_reporting is the default. I haven't changed anything configuration wise.
I will have to look back at my php version.

It also occurred to me that the code is being run to process an 'ajax' async request.
When errors or warnings are issued, they are sent in the async response. So I have
to use the javascript call back function to show me what is coming back. I may have
been neglecting to have javascript show the response string. I comes back in a load
of html markup. Unlike a synchronous request, the error markup is not processed
and displayed as html by the browser.

JK


> 
>>> 
>>> pirmd., 2020. g. 4. maijs, plkst. 01:45 — lietotājs Jeffry Killen (<jekillen@xxxxxxxxxxx>) 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
> 




[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux