I just attempted to create some Daily content, and after saving my node, I got the following errors:

* warning: Invalid argument supplied for foreach() in /home/myusername/mydomain.com/sites/all/modules/cck/content.module on line 1054.
* warning: Invalid argument supplied for foreach() in /home/myusername/mydomain.com/sites/all/modules/cck/content.module on line 1094.
* warning: Invalid argument supplied for foreach() in /home/myusername/mydomain.com/sites/all/modules/cck/content.module on line 347.

Not sure if this should be posted here in in the queue for Daily. Put it here since content.module showed. Not a big issue for me as this is just on a Test site for me. Hope it can help with future problems though!

Comments

yched’s picture

Status: Active » Postponed (maintainer needs more info)

The lines number don't seem to be against latest content.module file, so it's hard to say anything relevant.
Could you update to latest 6.x-1.x code, or, alternatively, paste the version of your conten.module file (the line that starts with // $Id: content.module at the top of the file)

kriskd’s picture

My version of CCK is up to date as of today (March 22) and I'm not getting any warnings to update to a more current version. Here is the Id line you requested:

$Id: content.module,v 1.278 2008/03/21 23:54:12 yched Exp $
yched’s picture

Er, something's obviously wrong, because line 1054 is } , line 1094 is inside a PHPdoc comment, and line 347 is empty.
I can't see how any of thos could issue a 'Invalid argument supplied for foreach()" error :-)

kriskd’s picture

Hmmm.... I must have a slightly different version of content.module than you. :-) Here are my lines 347-356:

  foreach ($type['extra'] as $key => $value) {
    // Some core 'fields' use a different key in node forms and in 'view'
    // render arrays.
    if (isset($value['view']) && isset($node->content[$value['view']])) {
      $node->content[$value['view']]['#weight'] = $value['weight'];
    }
    elseif (isset($node->content[$key])) {
      $node->content[$key]['#weight'] = $value['weight'];
    }
  }

1054-1075:

  foreach ($type['fields'] as $field) {
    $items = isset($node->$field['field_name']) ? $node->$field['field_name'] : array();

    // Make sure AHAH 'add more' button isn't sent to the fields for processing.
    unset($items[$field['field_name'] .'_add_more']);

    $module = $field_types[$field['type']]['module'];
    $function = $module .'_field';
    if (function_exists($function)) {
      $result = $function($op, $node, $field, $items, $teaser, $page);
      if (is_array($result)) {
        $return = array_merge($return, $result);
      }
      else if (isset($result)) {
        $return[] = $result;
      }
    }
    // test for values in $items in case modules added items on insert
    if (isset($node->$field['field_name']) || count($items)) {
      $node->$field['field_name'] = $items;
    }
  }

1094-1106:

    foreach ($type['fields'] as $field) {
      $items = isset($node->$field['field_name']) ? $node->$field['field_name'] : array();
      $result = content_field($op, $node, $field, $items, $teaser, $page);
      if (is_array($result)) {
        $return = array_merge($return, $result);
      }
      else if (isset($result)) {
        $return[] = $result;
      }
      if (isset($node->$field['field_name'])) {
        $node->$field['field_name'] = $items;
      }
    }

Thanks for taking the time to look at this!

yched’s picture

Status: Postponed (maintainer needs more info) » Active

Doh. That's because I probably shouldn't be answering tickets late at night. I was checking line numbers against my local copy of content.module, that has uncommitted chages. Such a dork, sorry about that :-/

Now, regarding the error themselves : could you try emptying your cache (using devel.module's 'empty cache', or manually deleting the content of the {cache_content} table ? The current code is supposed to initializa all of these ($type['fields'], $type['extra'] as arrays...)

kriskd’s picture

I emptied the table (it had 4 rows of data) then attempted to create Daily content again and got those same errors on the same lines.

I looked at the cache_content table after creating the content and it now contains the following date:

cid data expire created headers serialized
content_type_info [BLOB - 16.5 KiB] 0 1206309429 1
fieldgroup_data [BLOB - 52 B] 0 1206309449 1
content:5:5 [BLOB - 6 B] 0 1206309479 1

yched’s picture

Hm. Strange. I'll probably need to install this module to get what happens.

riverripper’s picture

Hi !
Just want to let you know, that I get the same errors plus even more when browsing
http://mydomain.com/myapp/node

* warning: Invalid argument supplied for foreach() in E:\develop\workspace\mydayz\sites\all\modules\custom\cck\content.module on line 1054.
* warning: Invalid argument supplied for foreach() in E:\develop\workspace\mydayz\sites\all\modules\custom\cck\content.module on line 1094.
* warning: Attempt to assign property of non-object in E:\develop\workspace\mydayz\sites\all\modules\custom\cck\content.module on line 343.
* warning: Invalid argument supplied for foreach() in E:\develop\workspace\mydayz\sites\all\modules\custom\cck\content.module on line 347.
* warning: Attempt to assign property of non-object in E:\develop\workspace\mydayz\modules\node\node.module on line 1006.
* warning: Attempt to assign property of non-object in E:\develop\workspace\mydayz\modules\node\node.module on line 1014.
* warning: Invalid argument supplied for foreach() in E:\develop\workspace\mydayz\sites\all\modules\custom\cck\content.module on line 1054.
* warning: Invalid argument supplied for foreach() in E:\develop\workspace\mydayz\sites\all\modules\custom\cck\content.module on line 1094.
* warning: Attempt to assign property of non-object in E:\develop\workspace\mydayz\sites\all\modules\custom\cck\content.module on line 343.
* warning: Invalid argument supplied for foreach() in E:\develop\workspace\mydayz\sites\all\modules\custom\cck\content.module on line 347.
* warning: Attempt to assign property of non-object in E:\develop\workspace\mydayz\modules\node\node.module on line 1006.
* warning: Attempt to assign property of non-object in E:\develop\workspace\mydayz\modules\node\node.module on line 1014.
* warning: Invalid argument supplied for foreach() in E:\develop\workspace\mydayz\sites\all\modules\custom\cck\content.module on line 1054.
* warning: Invalid argument supplied for foreach() in E:\develop\workspace\mydayz\sites\all\modules\custom\cck\content.module on line 1094.
* warning: Attempt to assign property of non-object in E:\develop\workspace\mydayz\sites\all\modules\custom\cck\content.module on line 343.
* warning: Invalid argument supplied for foreach() in E:\develop\workspace\mydayz\sites\all\modules\custom\cck\content.module on line 347.
* warning: Attempt to assign property of non-object in E:\develop\workspace\mydayz\modules\node\node.module on line 1006.
* warning: Attempt to assign property of non-object in E:\develop\workspace\mydayz\modules\node\node.module on line 1014.
* warning: Invalid argument supplied for foreach() in E:\develop\workspace\mydayz\sites\all\modules\custom\cck\content.module on line 1054.
* warning: Invalid argument supplied for foreach() in E:\develop\workspace\mydayz\sites\all\modules\custom\cck\content.module on line 1094.
* warning: Attempt to assign property of non-object in E:\develop\workspace\mydayz\sites\all\modules\custom\cck\content.module on line 343.
* warning: Invalid argument supplied for foreach() in E:\develop\workspace\mydayz\sites\all\modules\custom\cck\content.module on line 347.
* warning: Attempt to assign property of non-object in E:\develop\workspace\mydayz\modules\node\node.module on line 1006.
* warning: Attempt to assign property of non-object in E:\develop\workspace\mydayz\modules\node\node.module on line 1014.
* warning: Invalid argument supplied for foreach() in E:\develop\workspace\mydayz\sites\all\modules\custom\cck\content.module on line 1054.
* warning: Invalid argument supplied for foreach() in E:\develop\workspace\mydayz\sites\all\modules\custom\cck\content.module on line 1094.
* warning: Attempt to assign property of non-object in E:\develop\workspace\mydayz\sites\all\modules\custom\cck\content.module on line 343.
* warning: Invalid argument supplied for foreach() in E:\develop\workspace\mydayz\sites\all\modules\custom\cck\content.module on line 347.
* warning: Attempt to assign property of non-object in E:\develop\workspace\mydayz\modules\node\node.module on line 1006.
* warning: Attempt to assign property of non-object in E:\develop\workspace\mydayz\modules\node\node.module on line 1014.
* warning: Invalid argument supplied for foreach() in E:\develop\workspace\mydayz\sites\all\modules\custom\cck\content.module on line 1054.
* warning: Invalid argument supplied for foreach() in E:\develop\workspace\mydayz\sites\all\modules\custom\cck\content.module on line 1094.
* warning: Attempt to assign property of non-object in E:\develop\workspace\mydayz\sites\all\modules\custom\cck\content.module on line 343.
* warning: Invalid argument supplied for foreach() in E:\develop\workspace\mydayz\sites\all\modules\custom\cck\content.module on line 347.
* warning: Attempt to assign property of non-object in E:\develop\workspace\mydayz\modules\node\node.module on line 1006.
* warning: Attempt to assign property of non-object in E:\develop\workspace\mydayz\modules\node\node.module on line 1014.
* warning: Invalid argument supplied for foreach() in E:\develop\workspace\mydayz\sites\all\modules\custom\cck\content.module on line 1054.
* warning: Invalid argument supplied for foreach() in E:\develop\workspace\mydayz\sites\all\modules\custom\cck\content.module on line 1094.
* warning: Attempt to assign property of non-object in E:\develop\workspace\mydayz\sites\all\modules\custom\cck\content.module on line 343.
* warning: Invalid argument supplied for foreach() in E:\develop\workspace\mydayz\sites\all\modules\custom\cck\content.module on line 347.
* warning: Attempt to assign property of non-object in E:\develop\workspace\mydayz\modules\node\node.module on line 1006.
* warning: Attempt to assign property of non-object in E:\develop\workspace\mydayz\modules\node\node.module on line 1014.
* warning: Invalid argument supplied for foreach() in E:\develop\workspace\mydayz\sites\all\modules\custom\cck\content.module on line 1054.
* warning: Invalid argument supplied for foreach() in E:\develop\workspace\mydayz\sites\all\modules\custom\cck\content.module on line 1094.
* warning: Attempt to assign property of non-object in E:\develop\workspace\mydayz\sites\all\modules\custom\cck\content.module on line 343.
* warning: Invalid argument supplied for foreach() in E:\develop\workspace\mydayz\sites\all\modules\custom\cck\content.module on line 347.
* warning: Attempt to assign property of non-object in E:\develop\workspace\mydayz\modules\node\node.module on line 1006.
* warning: Attempt to assign property of non-object in E:\develop\workspace\mydayz\modules\node\node.module on line 1014.
* warning: Invalid argument supplied for foreach() in E:\develop\workspace\mydayz\sites\all\modules\custom\cck\content.module on line 1054.
* warning: Invalid argument supplied for foreach() in E:\develop\workspace\mydayz\sites\all\modules\custom\cck\content.module on line 1094.
* warning: Attempt to assign property of non-object in E:\develop\workspace\mydayz\sites\all\modules\custom\cck\content.module on line 343.
* warning: Invalid argument supplied for foreach() in E:\develop\workspace\mydayz\sites\all\modules\custom\cck\content.module on line 347.
* warning: Attempt to assign property of non-object in E:\develop\workspace\mydayz\modules\node\node.module on line 1006.
* warning: Attempt to assign property of non-object in E:\develop\workspace\mydayz\modules\node\node.module on line 1014.
* warning: Invalid argument supplied for foreach() in E:\develop\workspace\mydayz\sites\all\modules\custom\cck\content.module on line 1054.
* warning: Invalid argument supplied for foreach() in E:\develop\workspace\mydayz\sites\all\modules\custom\cck\content.module on line 1094.
* warning: Attempt to assign property of non-object in E:\develop\workspace\mydayz\sites\all\modules\custom\cck\content.module on line 343.
* warning: Invalid argument supplied for foreach() in E:\develop\workspace\mydayz\sites\all\modules\custom\cck\content.module on line 347.
* warning: Attempt to assign property of non-object in E:\develop\workspace\mydayz\modules\node\node.module on line 1006.
* warning: Attempt to assign property of non-object in E:\develop\workspace\mydayz\modules\node\node.module on line 1014.

Please let me know if you need further info.

Cheers,
Frank

yched’s picture

@krisd : You need to report your problem to daily.module : it sometimes calls node_view($node) where $node isn't an actual node
(even sometimes NULL) - happens in daily_view().

Other occurrences of the problem reported by riverripper, and others at http://drupal.org/node/242090 (marked duplicate), will need to be investigated separately. It's of course easier for us if people try to narrow down to a specific module being enabled on their site, like krisd did.

whatistocome’s picture

I am having same issue as http://drupal.org/node/242090

Disabled all modules except content, still getting error. Upgrade path was 5.7->6.1->6.2. Running CCK 6.x-1.x-dev. Have about a dozen content types from 5.7. Cleared cache. Gave going into each content type and resaved each to see if that would help. Still getting error.

~Jason

Frodo Looijaard’s picture

This problem was duplicated as daily issue 242995.
I think I have solved it, see the above issue for more information.
  Frodo

tvaughan’s picture

Version: 6.x-1.x-dev » 6.x-1.0-alpha

I get the following on content.module 6.x-1.0-alpha, not sure if it's related so I'm posting here for now:

Invalid argument supplied for foreach() in /home/xxx/public_html/travellocal/modules/cck/content.module on line 178.
Crell’s picture

I get the same as #12, using the alpha release. The relevant code snippet is in content_menu():

      foreach ($content_type['fields'] as $field) {
        $field_name = $field['field_name'];
        $items['admin/content/node-type/'. $type_url_str .'/fields/'. $field_name] = array(
          'title' => $field['widget']['label'],
          'page callback' => 'drupal_get_form',
          'page arguments' => array('_content_admin_field', $type_name, $field_name),
          'access arguments' => array('administer content types'),
          'file' => 'includes/content.admin.inc',
          'type' => MENU_LOCAL_TASK,
        );
        $items['admin/content/node-type/'. $type_url_str .'/fields/'. $field_name .'/remove'] = array(
          'title' => 'Remove field',
          'page callback' => 'drupal_get_form',
          'page arguments' => array('_content_admin_field_remove', $type_name, $field_name),
          'access arguments' => array('administer content types'),
          'file' => 'includes/content.admin.inc',
          'type' => MENU_CALLBACK,
        );
      }

Which indicates to me that it's trying to create menu items for each field when no fields yet exist. Sounds like just an if-empty check is needed.

Althogh I think chx would scream that you're doing it wrong, since you should be able to make a single menu entry with load functions to handle all field types / node types. He commented to me once "if you have a loop in your hook_menu(), you're wrong", but I don't know if that actually holds in all cases. :-) I'll have to ask him.

Crell’s picture

Update: I just asked his undistractedness, and he says that you should never loop for anything except LOCAL_TASKs. Those you still need to loop for, but everything else should be done sans-foreach. So $type_url_str and $field_name should become %node_type and %field, with corresponding load functions.

Frodo Looijaard’s picture

I think the original issue is covered by #242995: Invalid argument supplied for foreach().

The last few comments are also covered by #253490: Foreach warning when activating module in combination with CCK.

I tend to think this issue should be closed now the original problem is solved, in order to keep things manageable, but YMMV.

  Frodo

coltrane’s picture

I received this error right after I created a new content type (no fields yet) on a fresh 6.2 install with simplemenu 6.x-dev as the only other module installed. I'm not using the daily module so I don't think this error is limited to #242995: Invalid argument supplied for foreach() and it looks to be more like Crell's comment about trying to create menu items when no fields exist.

warning: Invalid argument supplied for foreach() in /var/www/d62/sites/all/modules/cck/content.module on line 178. on 6.x-alpha code

The difference for me from #253490: Foreach warning when activating module in combination with CCK is I received the error after creating a content type.

yched’s picture

http://drupal.org/node/253490 was marked duplicate

yched’s picture

http://drupal.org/node/254432 was marked duplicate :
"Invalid argument supplied for foreach() in /home/sunkodco/public_html/hkntmc/sites/default/modules/cck/content.module on line 178 - On creation of a new content type"

yched’s picture

http://drupal.org/node/254253 was marked duplicate
"Fresh install of drupal with some story nodes, imported from wordpress.

# warning: Invalid argument supplied for foreach() in /[...]/sites/www.friederschueler.de/modules/cck/content.module on line 1096.
# warning: Invalid argument supplied for foreach() in /[...]/sites/www.friederschueler.de/modules/cck/content.module on line 1136.
# warning: Invalid argument supplied for foreach() in /[...]/sites/www.friederschueler.de/modules/cck/content.module on line 353.
# warning: Invalid argument supplied for foreach() in /[...]/sites/www.friederschueler.de/modules/cck/content.module on line 1136.
"

coltrane’s picture

yched’s picture

http://drupal.org/node/255687 was marked duplicate :
(case when there are nodes whose content type has been deleted)
warning: Invalid argument supplied for foreach() in /mypath/html/sites/all/modules/cck/content.module on line 848.
warning: Invalid argument supplied for foreach() in /mypath/html/sites/all/modules/cck/content.module on line 1096.
warning: Invalid argument supplied for foreach() in /mypath/html/sites/all/modules/cck/content.module on line 1096.
warning: Invalid argument supplied for foreach() in /mypath/html/sites/all/modules/cck/content.module on line 1136.
warning: Invalid argument supplied for foreach() in /mypath/html/sites/all/modules/cck/content.module on line 353.
warning: Invalid argument supplied for foreach() in /mypath/html/sites/all/modules/cck/content.module on line 1136.
warning: Invalid argument supplied for foreach() in /mypath/html/sites/all/modules/cck/content.module on line 848.
warning: Invalid argument supplied for foreach() in /mypath/html/sites/all/modules/cck/content.module on line 1096.
warning: Invalid argument supplied for foreach() in /mypath/html/sites/all/modules/cck/content.module on line 1096.
warning: Invalid argument supplied for foreach() in /mypath/html/sites/all/modules/cck/content.module on line 1136.
warning: Invalid argument supplied for foreach() in /mypath/html/sites/all/modules/cck/content.module on line 353.
warning: Invalid argument supplied for foreach() in /mypath/html/sites/all/modules/cck/content.module on line 1136.

yched’s picture

http://drupal.org/node/256008 was marked duplicate
Aside from the usual suspects, also reports a line in content_permissions.module
warning: Invalid argument supplied for foreach() in /home/bignaija/public_html/sites/all/modules/cck/modules/content_permissions/content_permissions.module on line 34.

I'm currently in a period of time with extremely limited free-time to tackle this, so just doing issue queue housecleaning for now. I'll try to look into these as soon as I can, maybe this week-end ?

Mangaforce’s picture

do we have a fix for this yet ? As i seem to be going round in circles looking for it from duplicta thread to duplicta thread all with the same issue but no actual fix..

i have drupal 6.2 and CCK 6x Alpha ??

mysocom’s picture

fresh install 6.x-1.0-alpha Drupal 6.2 I have only story and page content type.

Add new content type > testimonials > warning: Invalid argument supplied for foreach() in content.module on line 178.

TuWebO’s picture

Hi all,
I am new drupal´s user, but same problem

warning: Invalid argument supplied for foreach() in content.module on line 178. when creating content type and even when I load a new module (Rotor 6.x-1.2).

I am using Drupal 6.2 and cck 6.x-1.0-alpha.

ikati’s picture

same here. just downloaded the CCK module the other night.

Tonight when I created a new content type, I got this:

warning: Invalid argument supplied for foreach() in /home/xyz/public_html/drupal/sites/all/modules/cck/content.module on line 178.

mysocom’s picture

I solve my problem by installing cck 6.x-1.x-dev

http://www.webskydev.com

KarenS’s picture

Status: Active » Fixed

#13 - We're using the same method used in core to create the node type menu since we're creating extensions to it, and core uses a foreach loop at that point. And the current code does a type cast to force the fields to an array.

Line 178 mentioned over and over is not even a foreach loop in the latest code, so this whole issue has been confused by lots of people reporting over and over that there was this bug in the alpha version.

Looking into all the line numbers reported (and adjusting for the fact that most of them are reporting the line number from the alpha version, it looks like the common thread is that they all come from using the following values which aren't arrays:

$type = content_types($type_name);
foreach ($type['tables'] as $table) {}
OR
foreach ($type['fields'] as $field {}

So I've added some code to content_types() to try to be sure that the returned array has an empty array for each of those keys if there's no valid data. This should catch most of the errors.

I'm closing this issue because of all the pollution of reports from the alpha version. If people still see foreach loops in the -dev version, please open a new issue and mark it that way.

Anonymous’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.

computer_jin’s picture

Hi every one ,
I am also having this same issue before many days and today i debub how can i solve this issue actually i was having error ....
warning: Invalid argument supplied for foreach() in \includes\form.inc on line 1193.
I am having this issue and when i debug and comment the code of checkboxes in my module than this error is resolved but i have to use this checkboxes ,check my code if i m missing some minor code and tell me how can i solve this ..

$form['payment_options']['business_payment_method']= array(
'#type' => 'checkboxes',
'#title'=> t('Payment Options'),
'#default_value' => variable_get('business_payment_method',$selected_payment),
'#options' => $payment_options,
);
I am using this tell me if you understand how can i solve this issue ...

Thanks in Advance

dungiis’s picture

Hello
I am currently running a drupal 6.13 and cck 6.x-3.x-dev module but got problem while browsing a Taxonomy. I found these errors.

# warning: Invalid argument supplied for foreach() in .../modules/cck/content.module on line 1335.
# warning: Invalid argument supplied for foreach() in .../modules/cck/content.module on line 1335.

Only a few taxonomies have problem while browsing them

Any recommendation ?

jvieille’s picture

Version: 6.x-1.0-alpha » 6.x-2.x-dev
Status: Closed (fixed) » Active

This does not seem to be solved yet.
I am having this error when previewing or saving a comment reply:
warning: Invalid argument supplied for foreach() in .../sites/all/modules/cck/content.module on line 1284

This is not critical as the the comment is properly saved and no error is displayed when viewing.

I installed the latest dev, but this did not help

pixelpreview@gmail.com’s picture

subscribe same warning after add a node with cck fields

artscoop’s picture

Warning: Invalid argument supplied for foreach() in /home/knt/lovelive/sites/all/modules/cck/content.module on line 242

Happens when viewing a freshly updated XML Sitemap, or after creating a new node.

anawillem’s picture

i am also getting the line:
warning: Invalid argument supplied for foreach() in /home/members/jellobrain/sites/jellobrain.com/web/sites/default/modules/cck/content.module on line 242.

paskainos’s picture

I'm experiencing this issue too, and haven't been able to determine where it's coming from. It appears the culprit is related to misdirected content. The front page shows an "n/a" at the bottom of the page, and the node div container code is:
<div class="node even node-unpublished teaser node-type-" id="node-">
Very strange... I've never seen that before. I'm digging around in the db, but nothing looks obvious at this point; no unpublished nodes, etc.

paskainos’s picture

Found it. In my case, the "Welcome to your Drupal website" starter page was ghosting on to the front page. Changing its status in the node table from 1 to 0 (or better yet DELETE FROM `node`...) fixed the problem.

NancyDru’s picture

Don't know if this is the same. This is 6.x-2.9.
"Invalid argument supplied for foreach() in /mnt/stor1-wc1-dfw1/378969/379186/www.thepoliticus.com/web/content/modules/acquia/cck/content.module on line 1244."

@paskainos: Check to make sure the node's input format is allowed to the role you are using. But it may also be a content type that no longer exists (that's why no type on "node-type-").

NancyDru’s picture

I just noticed one with "node-type-" and sure enough, the node table has an empty type column. As a matter of fact, there are 16 nodes like that.

paskainos’s picture

@NancyDru: Great tip (legacy node type)! Thanks for the heads up.

Crell’s picture

Issue summary: View changes
Status: Active » Closed (outdated)