28

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?

Darren
  • 13,050
  • 4
  • 41
  • 79
Mark Tomlin
  • 8,593
  • 11
  • 57
  • 72

1 Answers1

68

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;
Mark Tomlin
  • 8,593
  • 11
  • 57
  • 72
  • 3
    If you don't know the whole code, is better to add a conditional to the creation line, because the warning could be circumstantial. For example: if (!is_object($items[$i])) {$items[$i] = new stdClass;} $items[$i]->title = $crs_post_title; – Leopoldo Sanczyk Jan 13 '15 at 22:59
  • You mean instantiate. Not initialize. –  Apr 05 '17 at 06:48
  • 1
    @Mark Tomlin I had a similar issue which is now solved – Pallavi Prasad Jul 07 '17 at 12:34