如何修复PHP中的“从空值创建默认对象"警告 [英] How to fix 'Creating default object from empty value' warning in PHP
本文介绍了如何修复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
如何解决此错误?
推荐答案
事实证明,作者错过了一个非常简单的修复程序和通用的好习惯,即您在尝试设置属性之前应始终初始化对象.对此的非常简单的解决方法是,在错误尝试添加的变量之前添加一个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.
这还将通过以下修复方法解决
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屋!
查看全文