0

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
2
  • 2
    isset returns a boolean (true/false). You cannot iterate over that. Commented Aug 11, 2022 at 14:01
  • can you help me changing the code? my knowledge is bad Commented Aug 11, 2022 at 14:44

1 Answer 1

1

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)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.