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.
Comment | File | Size | Author |
---|---|---|---|
#42 | common.patch | 826 bytes | druliner |
#24 | Bildschirmfoto-5.png | 88.94 KB | fraweg |
#12 | child.zip | 429 bytes | thatjustin |
#12 | parent.zip | 414 bytes | thatjustin |
#7 | drupal-Casting-null-array-1711256-7.patch | 558 bytes | thatjustin |
Comments
Comment #1
marcingy CreditAttribution: marcingy commentedPlease provide steps of how to recreate on a fresh install of drupal core only.
Comment #2
P3t3r CreditAttribution: P3t3r commentedHe 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.
Comment #3
thatjustin CreditAttribution: thatjustin commentedI just reproduced with a pristine install of core alone.
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 outscaring 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?
Comment #4
marcingy CreditAttribution: marcingy commentedThanks for the info but I can't recreate on a local install which version of php are you using?
Comment #5
P3t3r CreditAttribution: P3t3r commentedPHP Version 5.3.2-1ubuntu4.17
Apache/2.2.14 (Ubuntu)
Comment #6
thatjustin CreditAttribution: thatjustin commentedComment #7
thatjustin CreditAttribution: thatjustin commentedI'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 aThis 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.Comment #8
sunThe 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.
Comment #9
ydahiSorry, 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).
Comment #10
ydahiPatch in #7 works for me.
Comment #11
marcingy CreditAttribution: marcingy commentedIt was set as works as designed because this is not a core bug.
Comment #12
thatjustin CreditAttribution: thatjustin commentedThis 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:
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.
Comment #13
thatjustin CreditAttribution: thatjustin commentedComment #14
marcingy CreditAttribution: marcingy commentedNo 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.
Comment #15
adammaloneFor 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.
Comment #16
busla CreditAttribution: busla commentedI´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?
Comment #17
mgiffordI 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.
Comment #18
DerekL CreditAttribution: DerekL commentedDitto.
Comment #19
twistor CreditAttribution: twistor commentedI think it might be the Advanced Help module causing this.
#1086990: Invalid argument supplied for foreach() when asking confirmation to enable required modules
Comment #20
Gus_ CreditAttribution: Gus_ commentedI 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.
Comment #21
adammaloneNot so sure about #19. I don't have advanced help installed or even on my server!
Comment #22
thatjustin CreditAttribution: thatjustin commentedIn 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.
Comment #23
junaidpvOn 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()
Comment #24
fraweg CreditAttribution: fraweg commentedHello,
I have the same issue with the "external link" module in drupal 7.16 .
Best regards
Frank
Comment #25
mgiffordGot 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...
Comment #26
P2790 CreditAttribution: P2790 commentedI received this issue too.
I had enabled, disabled then re-enabled clientside validation module.
Comment #27
Lukas von BlarerI 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:
Comment #28
Elin Yordanov CreditAttribution: Elin Yordanov commentedI 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!!
Comment #29
Tobias Jonch CreditAttribution: Tobias Jonch commentedHaving 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? :-(
Comment #30
marcingy CreditAttribution: marcingy commented@Tobias Jonch until clear steps to reproduce are provided the issue can not be solved.
Comment #31
vinmassaro CreditAttribution: vinmassaro commentedUpdating to the latest dev of Advanced Help fixed this for me. It was fixed in this issue: http://drupal.org/node/1086990
Comment #32
thatjustin CreditAttribution: thatjustin commentedI'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.
Comment #33
MrPhilbert CreditAttribution: MrPhilbert commentedDisabled advanced help. Warning went away.
Comment #34
MrPhilbert CreditAttribution: MrPhilbert commentedCuriously, I just re-enabled Advanced Help and there still is no warning?
Comment #35
muhammad.tanweer CreditAttribution: muhammad.tanweer commented#7: drupal-Casting-null-array-1711256-7.patch queued for re-testing.
Comment #36
muhammad.tanweer CreditAttribution: muhammad.tanweer commentedI 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
Comment #37
fengtanAlso experienced this issue which happened to come from Advanced Help (thank you #31).
Looks like this could be a duplicate of #1086990: Invalid argument supplied for foreach() when asking confirmation to enable required modules indeed.
Comment #38
mc0e CreditAttribution: mc0e commentedI'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.
Comment #39
mimes CreditAttribution: mimes commentedI 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.
Comment #40
ianthomas_ukAs 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.
Comment #41
tinny CreditAttribution: tinny commentedIt's because
foreach
expects an array and gets passed a null value.Comment #42
druliner CreditAttribution: druliner commentedOn 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.
Comment #43
josephdpurcell CreditAttribution: josephdpurcell commentedRelating issue to #1086990.