Home > Software engineering >  PHP Warning Invalid argument supplied for foreach() in stats.functions.php on line 71
PHP Warning Invalid argument supplied for foreach() in stats.functions.php on line 71

Time:08-12

I have a php bot (on IRC), and since I updated my php and mysql to the last version on CentOS I've come across with this error

PHP Warning: Invalid argument supplied for foreach() in stats.functions.php on line 71

Line 71:

foreach (isSet($nicks[$channel]) as $name => $value)

Code:

try
{
    global $db, $listas, $nicks, $channels, $time;
    $timeinc = time() - $time["inc"];
    $time["inc"] = time();
    $split = explode(",",$channels);
    foreach ($split as $channel)
    {
        if (!isset($channel))
        {
            continue;
        }
        if ($channel == "#pthelp")
        {
            foreach (isSet($nicks[$channel]) as $name => $value)
            {
                if (!isset($value) || strlen(trim($value)) < 1)
                {
                    continue;
                }
                $user = strtolower(addslashes($value));
                $nivel = checklevel($user);
                $membrorank = checkmembro($user);
                if ($nivel != "none" && $nivel != "Suspenso")
                {
                    $datames = date("n");
                    $dataano = date("Y");
                    // Rank Stats
                    if ($membrorank == 1 OR isSet($listas['candidatos'][$user]))
                    {
                        $in_rank = $db->get_row("SELECT tempo FROM membros_rankstats WHERE nick='". $user ."' AND mes='". $datames ."' AND ano='". $dataano ."'");
                        if ($in_rank)
                        {
                            $temporank = $in_rank->tempo   $timeinc;
                            if (isSet($listas['candidatos'][$user]))
                            {
                                $db->query("UPDATE

CodePudding user response:

isset returns a boolean, so you cannot iterate through that. Move the isset to the if-check above, and just iterate through the array:

if ($channel == "#pthelp" && isSet($nicks[$channel]))
{
    foreach ($nicks[$channel] as $name => $value)
  •  Tags:  
  • php
  • Related