Invalid argument supplied for foreach()

Started by FragaCampos, April 08, 2021, 11:14:25 PM

Previous topic - Next topic

FragaCampos

Hi there.
Everytime I check the who's online list, I get an error in the forum's log:


index.php?action=who
2: Invalid argument supplied for foreach()
File: Sources/Who.php
Line: 227


The line is the 5th in the following code:
// Are we showing spiders?
$spiderContext = array();
if (!empty($modSettings['show_spider_online']) && ($modSettings['show_spider_online'] == 2 || allowedTo('admin_forum')) && !empty($modSettings['spider_name_cache']))
{
foreach (safe_unserialize($modSettings['spider_name_cache']) as $id => $name)
$spiderContext[$id] = array(
'id' => 0,
'name' => $name,
'group' => $txt['spiders'],
'href' => '',
'link' => $name,
'email' => $name,
'is_guest' => true
);
}

$url_data = determineActions($url_data);


Any idea on what might be causing this?

SpacePhoenix

If you do a var_dump() on safe_unserialize($modSettings['spider_name_cache']) and on $modSettings['spider_name_cache'] what do you get for each?

FragaCampos

Sorry, I don't know how to do that...
Can you be more specific, please?


Quote from: SpacePhoenix on April 09, 2021, 05:12:02 AM
If you do a var_dump() on safe_unserialize($modSettings['spider_name_cache']) and on $modSettings['spider_name_cache'] what do you get for each?

SpacePhoenix

The error given by the foreach is basically because it expects to be given an array to work with. If it's not given an array to work with then you get the error that you've got

FragaCampos

What a mean is that I'm no coder, so I don't know what to do with the help you're giving me.
What should I do exactly to test that?

FragaCampos

I found out this topic and I reduced the number of spiders in the admin panel to under 256.
Doing that solved the problem, so this is definitely a bug with SMF.

SpacePhoenix

Quote from: FragaCampos on April 09, 2021, 05:26:56 PM
I found out this topic and I reduced the number of spiders in the admin panel to under 256.
Doing that solved the problem, so this is definitely a bug with SMF.

if you think there could be a bug then post the details of it at:

https://www.simplemachines.org/community/index.php?board=137.0

Including info like the version of SMF being used, PHP version being used, MySQL version being used and a list of all mods being used.

Others will try and replicate the bug to determine if it's actually a bug or something just down to a local install

Advertisement: