json_decode警告:从空值创建默认对象

时间:2014-01-15 07:27:42

标签: php joomla

我收到此错误并影响我的模块正常工作。我不知道如何解决它。大多数帮助网站说他们升级后得到了错误,但由于我没有升级,我不知道为什么会出现这个错误。

  

错误消息:警告:从空值创建默认对象   第125行的.... / aac / administrator / components / com_poweradmin / helpers / history.php。

以下从116行到154行。

  

第125行:“$ listPage-> params =(isset($ listPage-> params))?str_replace('&','&',$ listPage-> params):'';”

使用的代码:

 private static function updateHistoryState($post)
{
    if (!isset($_COOKIE['jsn-poweradmin-list-page']))
        return;

    $listPage = json_decode($_COOKIE['jsn-poweradmin-list-page']);
    if ($listPage == NULL)
        $listPage = json_decode(stripslashes($_COOKIE['jsn-poweradmin-list-page']));

    $listPage->params = (isset($listPage->params)) ? str_replace('&', '&', $listPage->params) : '';
    $id = array();

    if (isset($post['id']) && is_numeric($post['id']))
        $id[] = $post['id'];
    else if (isset($post['id']) && is_array($post['id']))
        $id = array_merge($id, $post['id']);

    if (isset($post['cid']) && is_numeric($post['cid']))
        $id[] = $post['cid'];
    else if (isset($post['cid']) && is_array($post['cid']))
        $id = array_merge($id, $post['cid']);

    $isDelete = (int)preg_match('/\.?(delete|remove|trash)$/i', $post['task']);

    if (count ($id) && (is_numeric($id) || is_array($id))) {
        // Bypass if any of id list is not a number
        if (is_array($id)) {
            foreach ($id as $i) {
                if (!is_numeric($i)) {
                    return;
                }
            }
        }

        $dbo = JFactory::getDBO();
        $dbo->setQuery("UPDATE #__jsn_poweradmin_history SET is_deleted={$isDelete} WHERE list_page_params LIKE '{$listPage->params}' AND object_id IN (".implode(',', $id).")");
        @$dbo->query();
    }
}

1 个答案:

答案 0 :(得分:0)

这不是一个错误,而是一个警告。

您尝试解码的JSON似乎格式不正确,并且json_decode无法返回类型为stdClass的对象。可能json_decode返回NULL。

基本上警告是关于尝试将属性分配给尚未初始化为stdClass对象的变量。

相关问题