All warnings when I clean my cache and not only ...

Invalid argument supplied for foreach() fb_social.module:186 [warning]
Invalid argument supplied for foreach() fb_social.module:186 [warning]

Invalid argument supplied for foreach() fb_social.module:186 [warning]
Invalid argument supplied for foreach() fb_social.module:186 [warning]
Invalid argument supplied for foreach() fb_social.module:142 [warning]
Invalid argument supplied for foreach() fb_social.module:142 [warning]
Invalid argument supplied for foreach() fb_social.module:142 [warning]
Invalid argument supplied for foreach() fb_social.module:142 [warning]

The patch that fixes is just wrapping the foreach in an if...

I can see in the latest 7.x-2.x-dev there is an iff added and my patch may be unneeded... Its a good idea to always wrap the foreach in if-s though....

Mark it as not necessary if it is...

diff -upr fb_social/fb_social.module fb_social-new/fb_social.module
--- fb_social/fb_social.module	2011-11-22 16:34:35.000000000 +0100
+++ fb_social-new/fb_social.module	2012-11-08 17:48:05.000000000 +0100
@@ -139,6 +139,7 @@ function fb_social_block_info(){
   // load all presets
   $presets = fb_social_get_presets();
 
+if ( ! empty( $presets ) ) {
   foreach ( $presets as $preset ) {
     if ($preset->settings['block']) {
       $blocks[$preset->name] = array(
@@ -146,6 +147,7 @@ function fb_social_block_info(){
       );
     }
   }
+  }
   return $blocks;
 }
 
@@ -183,6 +185,7 @@ function fb_social_field_extra_fields(){
   $extras = array();
   $presets = fb_social_get_presets();
 
+if ( ! empty( $presets ) ) {
   foreach ( $presets as $preset ) {
     $plugin = fb_social_fb_plugin_load($preset->plugin_type);
     $function = ctools_plugin_get_function($plugin, 'content_extra_fields callback');
@@ -190,6 +193,7 @@ function fb_social_field_extra_fields(){
       $function($extras, $preset);
     }
   }
+  }
   return $extras;
 }
 

Comments

DamienMcKenna’s picture

Title: fix php warnings like "Invalid argument supplied for foreach() fb_social.module:186" - patch included » fix php warnings like "Invalid argument supplied for foreach() fb_social.module:186"

Simplified the title (no need to say "patch included".

DamienMcKenna’s picture

Status: Needs review » Needs work

This actually needs a patch file.