MYBB 警告 [2] count():参数必须是数组或实现 Countable 的对象 - 行:906

Posted

技术标签:

【中文标题】MYBB 警告 [2] count():参数必须是数组或实现 Countable 的对象 - 行:906【英文标题】:MYBB Warning [2] count(): Parameter must be an array or an object that implements Countable - Line: 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);

【问题讨论】:

【参考方案1】:

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

if(is_array($postsdone))
   $postcounter = count($postsdone);

else
   // set $postcounter to whatever you want it be...

【讨论】:

以上是关于MYBB 警告 [2] count():参数必须是数组或实现 Countable 的对象 - 行:906的主要内容,如果未能解决你的问题,请参考以下文章