This seems to happen consistently for me, even from a fresh setup. Today it was on 7.15.
If you enable a module that requires another installed and disabled module to be enabled, it works, yet this error is thrown.
It seems to me to be an issue with core since it is showing up in specific modules' issues queues. Linkit Field Group Multiple Form Builder

The exact error I received was Invalid argument supplied for foreach() in element_children() (line 6300 of [DRUPAL_HOME]/includes/common.inc).

I haven't tested enough to be sure that the issue is indeed enabling a disabled module as a dependency, but I think that is it.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

marcingy’s picture

Status: Active » Postponed (maintainer needs more info)

Please provide steps of how to recreate on a fresh install of drupal core only.

P3t3r’s picture

He described the steps, no?

Take any non-core module which has different entries in the modules list, say A and B, where A requires B. Enable B only. The system will correctly enable A as well, but it will throw the above error.

This happens with every possible module that I've tried on this website, so it's definitely not some module-specific problem.

thatjustin’s picture

Status: Postponed (maintainer needs more info) » Active
FileSize
57.99 KB

I just reproduced with a pristine install of core alone.

  1. Fresh install
  2. Disable the Comment module, Save
  3. Enable the forum module, without enabling Comment

The next screen has the attached error.

Correct me if I am wrong, but that should mean that it is a core issue, since it is a core function to handle module dependency.

This Google search shows that it is occurring across the board. I am not a developer per se, or a frequent contributor to drupal.org (yet), but I think we should consolidate the discussion about this bug somewhere, probably here. My completely off-the-cuff guess is that it is a small fix, but is perhaps freaking out scaring away a lot of first time Drupalers when they see an error just after enabling some modules. You can see that here, somewhat.

I'm taking the bold move of re-opening to active. If one of the more senior folk that watches the core queue knows better, please close this down. I believe it is minor since (as far as I can tell), it doesn't actually break anything, just throws an error.

Also, can someone with some authoritative knowledge say whether or not we should drop comments in all of those other module's Issue queues that seem to be having this problem?

marcingy’s picture

Status: Active » Postponed (maintainer needs more info)

Thanks for the info but I can't recreate on a local install which version of php are you using?

P3t3r’s picture

PHP Version 5.3.2-1ubuntu4.17
Apache/2.2.14 (Ubuntu)

thatjustin’s picture

[root@localhost modules]# php -v
PHP 5.3.8 (cli) (built: Sep 28 2011 17:13:51) 
Copyright (c) 1997-2011 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2011 Zend Technologies
[root@localhost modules]#
thatjustin’s picture

Title: Enabling diabled modules causes error: Invalid argument supplied to element_children() » Enabling disabled modules causes error: Invalid argument supplied to element_children()
Version: 7.15 » 7.x-dev
Status: Postponed (maintainer needs more info) » Needs review
FileSize
558 bytes

I've done some more research. $elements here is null sometimes. Specifically, when installing modules with a transitive dependency. (If Comment and Forum are both disabled, and Forum is dependent on Comment, and you enable Forum, that is what I am calling a transitive dependency). The first argument to every foreach() needs to be an array, and in the case that it is null, you get a

Invalid argument supplied for foreach() in...

This is discussed in a comment here on php.net.

I'm submitting a patch. I thought it made sense to cast $elements to an array, as opposed to checking for null-ness or array-ness in a conditional. Perhaps it should be the other way around, or some other solution. I tested this patch locally and it works.

I'm not sure why this hasn't been caught earlier, which makes me wonder if I am correctly understanding the situation here. Perhaps $elements should never be null, and there is an issue earlier up the stack, I'm not sure.

sun’s picture

Component: configuration system » base system
Status: Needs review » Closed (works as designed)
Issue tags: -core

The suggested fix only hides the actual problem.

If $elements is not an array, then some module is declaring a child element in a form array or an render array that is not an array.

The guilty module has to be fixed instead.

ydahi’s picture

Version: 7.x-dev » 7.15
Status: Closed (works as designed) » Active

Sorry, thread status was set to "closed", re-opened. Will test patch in #7 tomorrow and provide feedback. Thanks for your prompt response.

Fresh install D7.15
PHP 5.3.10-1ubuntu3.2
Apache/2.2.22 (Ubuntu)

Error:
Warning: Invalid argument supplied for foreach() in element_children() (line 6300 of /var/www/SPG/includes/common.inc).

ydahi’s picture

Patch in #7 works for me.

marcingy’s picture

Status: Active » Closed (works as designed)

It was set as works as designed because this is not a core bug.

thatjustin’s picture

FileSize
414 bytes
429 bytes

This is a core issue, and I believe I can prove it. If you take the two attached modules, which are completely empty except that the child is dependent on the parent, and enable only the child, you get the error:

Warning: Invalid argument supplied for foreach() in element_children() (line 6301 of xxx/includes/common.inc).

The issue is in some way due to how core is handling module dependencies. I think we can agree that it is a function of core to handle module installation and dependency resolution, which consistently throws this error.

I agree with sun that my patch masks the error, but I don't know how to fix the underlying cause. marcingy, I'm curious if you get the error with these two modules, and if you do, if you'd agree that it is a core issue.

thatjustin’s picture

Status: Closed (works as designed) » Active
marcingy’s picture

No I don't get any errors either on the you need enable to parent screen or the module screen after confirming. This is also on php 5.3.8.

adammalone’s picture

For me this error is intermittent. I usually get it whilst in the admin overlay - I notice the error on the website underneath the overlay. On page refresh the error is gone and I've not yet been able to track down exactly which of my installed modules is causing the error.

busla’s picture

I´m using MAMP with two instances of Drupal, local and dev, and I (git) push and pull between them. I´m getting the error on local but not on dev. Weird :/

How can I debug this?

mgifford’s picture

I just got this error when installing a feature. There were a number of other modules that were being added on at the same time that were dependancies.

DerekL’s picture

Ditto.

twistor’s picture

Gus_’s picture

I can confirm this post. I have tested multiple times and did not receive an error until after Advanced Help module was installed and I received the identical error message.

adammalone’s picture

Not so sure about #19. I don't have advanced help installed or even on my server!

thatjustin’s picture

In summation up to now: this is extremely likely a core issue, not caused by any of the multiple different modules that triggers it. It is triggered by recursive dependencies, and it is complicated by the fact that it doesn't happen for everyone, but clearly happens frequently. It does happen for me on a stock installation.

I'm not sure what needs to happen next, but there is clearly something up, since the blank modules in #12 trigger it for me, probably many others, and not so for still others.

junaidpv’s picture

On a fresh installtion of 7.16 I could not reproduc the issue by following the steps specified at #1711256-3: Enabling disabled modules causes error: Invalid argument supplied to element_children()

fraweg’s picture

FileSize
88.94 KB

Hello,

I have the same issue with the "external link" module in drupal 7.16 .

Best regards
Frank

mgifford’s picture

Got this again enabling panels. Have to look at foreach ($elements as $key => $value) { to see what module might be causing this to happen.

http://api.drupal.org/api/drupal/includes!common.inc/function/element_ch...

P2790’s picture

I received this issue too.
I had enabled, disabled then re-enabled clientside validation module.

Warning: Invalid argument supplied for foreach() in element_children() (line 6300 of /home/e-smith/files/ibays/sota3/html/includes/common.inc).
Warning: Invalid argument supplied for foreach() in element_children() (line 6300 of /home/e-smith/files/ibays/sota3/html/includes/common.inc).
Warning: Invalid argument supplied for foreach() in element_children() (line 6300 of /home/e-smith/files/ibays/sota3/html/includes/common.inc).
Warning: Invalid argument supplied for foreach() in element_children() (line 6300 of /home/e-smith/files/ibays/sota3/html/includes/common.inc).
Lukas von Blarer’s picture

I am having this issue as well. I am not sure what caused this, but I updated ctools and metatag to the latest dev. I am getting these messages:

    Warning: Invalid argument supplied for foreach() in element_children() (line 6300 of //includes/common.inc).
    Warning: Cannot use a scalar value as an array in drupal_render() (line 5767 of /includes/common.inc).
    Warning: Cannot use a scalar value as an array in drupal_render() (line 5822 of /includes/common.inc).
    test
Elin Yordanov’s picture

I had the same issue half an hour ago. Reading this issue and the one for advanced help, I have given it a try to disable 'advanced help' module, and the warning is gone!!

Tobias Jonch’s picture

Having this very annoying issue as well. Started after installing 'Inline Form Errors' module, and disabling the Adv. Help module did nothing for me.

If there's a working patch, why wasn't it included in the latest minor update? :-(

marcingy’s picture

Status: Active » Postponed (maintainer needs more info)

@Tobias Jonch until clear steps to reproduce are provided the issue can not be solved.

vinmassaro’s picture

Updating to the latest dev of Advanced Help fixed this for me. It was fixed in this issue: http://drupal.org/node/1086990

thatjustin’s picture

Status: Postponed (maintainer needs more info) » Closed (cannot reproduce)

I'm the OP and I have tried but I can't reliably reproduce my issue. Closing. I tend to think that this is an issue caused by each offending module.

MrPhilbert’s picture

Disabled advanced help. Warning went away.

MrPhilbert’s picture

Curiously, I just re-enabled Advanced Help and there still is no warning?

muhammad.tanweer’s picture

Status: Closed (cannot reproduce) » Needs review
muhammad.tanweer’s picture

I had a site where I upgraded from D6 to D7 and I received the same error on product dependencies edit tab. I did this patch and it worked.

Muhammad
www.app-desk.com

fengtan’s picture

Also experienced this issue which happened to come from Advanced Help (thank you #31).

  • Disabling Advanced Help made the warning go away
  • Re-enabling Advanced Help made the warning go back

Looks like this could be a duplicate of #1086990: Invalid argument supplied for foreach() when asking confirmation to enable required modules indeed.

mc0e’s picture

I'm seeing this problem on a site I just moved from one host to another. The problem did not show up on the old host, and does on the new host. I have made no changes to drupal files or the database.

The PHP version has changed, and presumably aspects of the apache setup.

My guess is that $elements has sometimes been null for some time, but that newer PHP versions complain while older ones didn't. That seems to be born out by Eksempel #2 (example) at the following url. (note that the /en/ version is different, but in fact the text is mostly english anyway).

http://docs.php.net/manual/da/language.types.array.php

The increase in writes to the watchdog table is not particularly welcome. The patch in #7 therefore has some value besides papering over the problem. Also, the meaning of the warnings is fairly obscure. It'd be better though if it also recorded a single more helpful warning, even if that is still an interim solution.

mimes’s picture

I cannot reproduce this issue with Advanced Help, or under the circumstances posted by the original reporter in comment #3 with Drupal 7.24 or 7.x.

ianthomas_uk’s picture

Issue summary: View changes
Status: Needs review » Closed (duplicate)

As stated in #8, #7 is not a fix for the problem.

It looks like this was a duplicate of #1086990: Invalid argument supplied for foreach() when asking confirmation to enable required modules which was fixed in advanced_help-7.x-1.1

If you are still seeing this problem and aren't running an older version of advanced_help then please reopen the issue with clear steps to reproduce that can be followed by another developer. Ideally this means starting with a fresh installation of the latest version of D7. If those steps involve installing one or more contrib modules, then you should file a new bug for that contrib module, but mention this one so the maintainer can see how this was fixed.

There is no point reopening this issue without adding steps to reproduce, as there is not enough information to fix any potential bug.

tinny’s picture

It's because foreach expects an array and gets passed a null value.

druliner’s picture

FileSize
826 bytes

On our system it wasn't because $elements was null, it was because it was empty. Enclosing the foreach with this fixed it.

if ( ! empty($elements) ){
......
}

I know hacking core is discouraged but I've included a patch anyway.

josephdpurcell’s picture