【问题标题】:MYBB Warning [2] count(): Parameter must be an array or an object that implements Countable - Line: 906MYBB 警告 [2] count():参数必须是数组或实现 Countable 的对象 - 行:906
【发布时间】:2018-10-19 18:35:24
【问题描述】:

如果重复,对不起,但我不知道如何在 PHP 7.24 上修复这个 MyBB 1.8.15 错误 警告 [2] count():参数必须是数组或实现 Countable 的对象 - 行:906

    // Build the threaded post display tree.
    $query = $db->query("
        SELECT p.username, p.uid, p.pid, p.replyto, p.subject, p.dateline
        FROM ".TABLE_PREFIX."posts p
        WHERE p.tid='$tid'
        $visible
        ORDER BY p.dateline
    ");
    while($post = $db->fetch_array($query))
    {
        if(!$postsdone[$post['pid']])
        {
            if($post['pid'] == $mybb->input['pid'] || ($isfirst && !$mybb->input['pid']))
            {
                $postcounter = count($postsdone);
                $isfirst = 0;
            }
            $tree[$post['replyto']][$post['pid']] = $post;
            $postsdone[$post['pid']] = 1;
        }
    }

    $threadedbits = buildtree();
    $posts = build_postbit($showpost);
    eval("\$threadexbox = \"".$templates->get("showthread_threadedbox")."\";");
    $plugins->run_hooks("showthread_threaded");
}

第 906 行出错的是$postcounter = count($postsdone);

【问题讨论】:

    标签: php mybb


    【解决方案1】:

    如果 $postsdone 未被评估为“可计数”(在这种情况下,如果它不是数组),则会发生此错误。我将在执行 count($postsdone) 之前验证 $postsdone 是一个数组。例如:

    if(is_array($postsdone)){
       $postcounter = count($postsdone);
    }
    else{
       // set $postcounter to whatever you want it be...
    }
    

    【讨论】:

      猜你喜欢
      • 2018-12-19
      • 1970-01-01
      • 2018-09-10
      • 2019-08-15
      • 2020-01-18
      • 2020-01-27
      • 2019-06-20
      • 2020-04-08
      • 2019-10-18
      相关资源
      最近更新 更多