help: Undefined property: stdClass notice question

193 views
Skip to first unread message

Ruud van Lent

unread,
Feb 27, 2016, 1:35:22 PM2/27/16
to Joomla! General Development
Hi,

A user of one of my plugins just reported the following notice:
Notice: Undefined property: stdClass::$language in C:\web\IWWA\plugins\content\myplugin\myplugin.php on line 140
Notice: Undefined property: stdClass::$fulltext in C:\web\IWWA\plugins\content\myplugin\myplugin.php on line 504

when looking at those lines I have the following code:

140 > $url = JRoute::_(ContentHelperRoute::getArticleRoute($article->slug, $article->catid, $article->language), false, ($uri->isSSL() == '1' ? '1' : '-1'));
504 > preg_match_all('/<img .*src=["|\']([^"|\']+)/i', $article->introtext . $article->fulltext, $matches_image);

It is a content plugin. The error generated is on a Joomla installation with flexicontent.
So it looks like the $article->language and $article->fulltext are causing problems. Could this be because these are 'empty'?

Could this be flexicontent related or is my code missing a check on the existence of these classes?

Hope somebody can share a light :)

Hannes Papenberg

unread,
Feb 27, 2016, 1:39:50 PM2/27/16
to joomla-de...@googlegroups.com
You need to check if those attributes exist, because the
onPrepareContent event is called by several different areas of Joomla,
not all of them sending in a full article. So you might just get an
object with a text attribute with the content to modify and nothing else.

Hannes

Am 27.02.2016 um 19:35 schrieb Ruud van Lent:
> Hi,
>
> A user of one of my plugins just reported the following notice:
> Notice: Undefined property: stdClass::$language in C:\web\IWWA\plugins\content\myplugin\myplugin.php on line 140
> Notice: Undefined property: stdClass::$fulltext in C:\web\IWWA\plugins\content\myplugin\myplugin.php on line 504
>
> when looking at those lines I have the following code:
>
> 140 > $url =
> JRoute::_(ContentHelperRoute::getArticleRoute($article->slug,
> $article->catid,*$article->language*), false, ($uri->isSSL() == '1' ?
> '1' : '-1'));
> 504 > preg_match_all('/<img .*src=["|\']([^"|\']+)/i',
> $article->introtext . *$article->fulltext*, $matches_image);
>
> It is a content plugin. The error generated is on a Joomla
> installation with flexicontent.
> So it looks like the $article->language and $article->fulltext are
> causing problems. Could this be because these are 'empty'?
>
> Could this be flexicontent related or is my code missing a check on
> the existence of these classes?
>
> Hope somebody can share a light :)
> --
> You received this message because you are subscribed to the Google
> Groups "Joomla! General Development" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to joomla-dev-gene...@googlegroups.com
> <mailto:joomla-dev-gene...@googlegroups.com>.
> To post to this group, send email to
> joomla-de...@googlegroups.com
> <mailto:joomla-de...@googlegroups.com>.
> Visit this group at https://groups.google.com/group/joomla-dev-general.
> For more options, visit https://groups.google.com/d/optout.

Ruud van Lent

unread,
Feb 27, 2016, 1:56:05 PM2/27/16
to Joomla! General Development
Hi Hannes, thanks for looking over my shoulder :)

Can I use this function: bool property_exists ( mixed $class , string $property )
and if false how can I set the value to something that will not raise the notice?

What is a best practise for this: I have looked at other content plugins, but cannot seem to find one that does this check? Am I just unlucky to run into this? Should I check all the properties?

TIA Ruud
Reply all
Reply to author
Forward
0 new messages