1

I recently uploaded a Joomla 2.5 site from my dev server to our host and discovered that one of the extensions that is a part of our site uses PHP code that is no longer "acceptable" in PHP 5.5. I keep getting the

Warning: Creating default object from empty value .../helper.php on line 36

Since it is only one error I'm getting, I'd like to fix the php instead of simply hiding the warning.The relevant code line generating the error is:

$lists[$i]->id = $row->id;

I am aware that I should add a new StdClass; call right before the error with the variable it is trying to access per Mark Tomlin's response in this post How to fix 'Creating default object from empty value' warning in PHP

However, being a php newb I'm not sure how that would look in the code below.

{
public static function getList($params)
{

    $items = modArticlesLatestHelper::getList($params);

    $text_length = intval($params->get( 'preview_count', 200) );
    $tags       = $params->get('strip_tags', "a,i,br");

    $i=0;
    $lists  = array();
    foreach ( $items as $row )
    {
        //process content plugins
        $text = JHTML::_('content.prepare',$row->introtext);
        $lists[$i]->id = $row->id;
        $lists[$i]->thumb = self::getThumb($row->introtext,$params->get('thumb_width',160));
        $lists[$i]->created = $row->created;
        $lists[$i]->modified = $row->modified;
        $lists[$i]->link = $row->link;
        $lists[$i]->title = htmlspecialchars( $row->title );
        $lists[$i]->introtext = self::prepareContent( $text, $text_length, $tags);
        $i++;
    }

    return $lists;
}

Thanks in advance for your suggestions, ideas and help.

3
  • holy moly, I miss (not) seeing joomla code. Commented Aug 8, 2014 at 14:42
  • Should I have not posted so much code? Commented Aug 8, 2014 at 14:56
  • no it's good, I just never liked joomla code, and it looks like it hasn't improved that much after so many years. you should also turn off display_errors on production Commented Aug 8, 2014 at 15:00

1 Answer 1

4

Create object before setting property

$lists[$i] = new stdClass();
$lists[$i]->id = $row->id;

Or single line solution

$lists[$i] = (object)array('id' => $row->id);
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, about 30 seconds after I posted I tried that approach and it did the trick. Man, I feel pretty silly for not recognizing/trying it before posting. Thank you for your quick and accurate fix.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.