如何修复 PHP 中的“从空值创建默认对象"警告 [英] How to fix 'Creating default object from empty value' warning in PHP

查看:30
本文介绍了如何修复 PHP 中的“从空值创建默认对象"警告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从我的 joomla 安装中收到以下错误.

I get the following error from a joomla install that I have.

Warning: Creating default object from empty value in  /modules/mod_continuous_rss_scrolling/helper.php on line 54

我该如何解决这个错误?

How do I fix this error?

推荐答案

事实证明,作者遗漏了一个非常简单的修复方法和一般的良好做法,即在尝试设置属性之前始终应初始化对象.解决这个问题的非常简单的方法是在它试图访问的变量出现错误之前添加一个 new StdClass; 调用.

As it turns out, the author missed a very simple fix and general good practice that you should always initialize your object before you try to set a property. The very simple fix for this is simply to add a new StdClass; call right before the error with the variable it is trying to access.

$items[$i] = new StdClass;
$items[$i]->title   = $crs_post_title;

第一行将修复显示警告.

That first line will fix the warning from showing up.

这也将通过以下修复解决 /components/com_community/models/activities.php on line 387 中的问题.

This would also fix the problem in /components/com_community/models/activities.php on line 387 with the following fix.

$commentsResult[$comment->type . '-' . $comment->contentid] = new StdClass;
$commentsResult[$comment->type . '-' . $comment->contentid]->_comment_count = 0;

这篇关于如何修复 PHP 中的“从空值创建默认对象"警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆