Notice: Undefined property: stdClass error on front end

Matt Weick picture Matt Weick · Sep 15, 2013 · Viewed 7.1k times · Source

I can't figure out how to make this line defined. If anyone can offer assiatnce that would be appreciated, probably something very simple.

This line: $value = $value->published;

Keeps giving me this error - Notice: Undefined property: stdClass::$published

public static function published($value, $i, $img1 = 'tick.png', $img0 = 'publish_x.png', $prefix = '')
{var_dump($value); die();
    if (is_object($value))
    {
        $value = $value->published;
    }

    $img = $value ? $img1 : $img0;
    $task = $value ? 'unpublish' : 'publish';
    $alt = $value ? JText::_('JPUBLISHED') : JText::_('JUNPUBLISHED');
    $action = $value ? JText::_('JLIB_HTML_UNPUBLISH_ITEM') : JText::_('JLIB_HTML_PUBLISH_ITEM');

    $href = '
    <a href="#" onclick="return listItemTask(\'cb' . $i . '\',\'' . $prefix . $task . '\')" title="' . $action . '">'
        . JHtml::_('image', 'admin/' . $img, $alt, null, true) . '</a>';

    return $href;
}

Answer

George Brighton picture George Brighton · Sep 15, 2013

These lines don't make much sense:

$value = new stdClass();
$value = $value->published; // attempt to read from an undefined property

You're creating a clean object with no properties, then trying to read from one - hence the error. What are these lines meant to do?

If I had to make a stab in the dark, try removing $value = new stdClass(); and see if that now works. I imagine you want the first parameter of your published() function to accept either a boolean or object.