Download & Extend

"Invalid argument supplied for foreach()" error in logs

Project:RelatedContent
Version:5.x-1.6
Component:Code
Category:bug report
Priority:minor
Assigned:TBarregren
Status:postponed (maintainer needs more info)

Issue Summary

Hi,

I noticed a lot of messages like the following in my log files:

Invalid argument supplied for foreach() in C:\Users\Steven Hines\Documents\projects\mumsrock\htdocs\sites\all\modules\relatedcontent\relatedcontent.module on line 208.

This only appears on pages where related content is enabled but no related content has been assigned to the page. It seems to be caused by the $output variable being null.

Please find attached a hacked together patch to stop these log entries from happening. An alternative to the way I've done it is to set $output to be null explicitly at the beginning of the theme_relatedcontent function and leave it to be null for pages where related content is enabled but no content has been assigned. This would enable you to get rid of the (rather hacky) assigning of an empty string to the $output variable in my suggested patch.

I've recently got into Drupal / PHP and this is my first patch, so please be gentle!!

Thanks for a great module by the way,

Cheers,
Steve

AttachmentSize
relatedcontent.module.patch633 bytes

Comments

#1

Assigned to:Anonymous» TBarregren
Status:needs work» postponed (maintainer needs more info)

Thank you for your bug report.

Unfortunately, I'm not able to reproduce your error. Have you modified the code? I'm wondering because the cited error message says that the foreach() is on line 208, but in 5.x-1.6 it is actually on line 205. Moreover, $output can't be null, which you claim, since the only call to theme_relatedcontent() is done only if $output != null (see line 458). Hence, I suspect you have modified the code and introduced the bug yourself. :-) If not, please, give me further details on how to reproduce the error.

#2

Bizarre. I'm not sure where that 208 came from. I just reverted back the 1.6 version of the file and it was indeed on line 205, not 208. My apologies for that. I've had a few late nights lately so it's possible my copy + paste skills have suffered along with a few other things :-)

I haven't modified any of the contributed or core code; I try to avoid that where possible. That's not to say that something else I've installed isn't causing the problem though. That'll be the next thing I investigate.

As I say, I'm a PHP newbie, so when I claimed that $output was null, perhaps I should have been more specific, i.e. isset($output) was not returning a value of 1 when I printed it to the php error log.

I've got quite a bit on at the moment, but when I get a chance I'll look a bit further into this to see if I can produce some steps to reproduce.

Thanks,
Steve

#3

just search for all foreaches in the code and wrap an if-some-var-empty around them ...

nobody click here