We are seeing this error occurring very regularly in our logs:
Warning: Invalid argument supplied for foreach() in _mailchimp_lists_subscription_has_changed() (line 229 of /var/www/prod/csp/site/modules/contrib/mailchimp/modules/mailchimp_lists/mailchimp_lists.module)
However, I've spent a long time trying to debug it or reproduce it and could not. I suspect it could be something to do with people who haven't visited the site for a while and are lacking data (from a newer version of the module), or some configuration problem, but honestly I don't know why it could be NULL.
But regardless of why it happens, logically speaking it can be easily prevented with a simple change to add ?? [] before the foreach.
Logically this makes sense because the result of getInterestGroups() can be NULL:
public function getInterestGroups() {
if (isset($this->values['interest_groups'])) {
return $this->values['interest_groups'];
}
return NULL;
}So this should be handled in the code.
| Comment | File | Size | Author |
|---|---|---|---|
| #5 | mailchimp-3357696-new-interest-groups-null-5.patch | 1.74 KB | aprice42 |
Comments
Comment #2
rob230 commentedComment #3
rob230 commentedAlternatively it should return an empty array instead of NULL.
Comment #4
rob230 commentedThat actually still didn't fix the error, because it turns out it can be FALSE as well. At least that is what is on the entity, I assume it is the same after an entity is saved.
Notice "subscribe" is also "0" rather than FALSE, so maybe this is data from an earlier version of the module which is causing it to have errors. I don't know if there should be something done to fix the data, e.g. to make it like this:
But here is a patch to just fix the PHP error.
Comment #5
aprice42 commented@Rob230 I wonder if this patch might resolve the issue? Just adding a check over that entire block of code to see if the new_interest_groups exists and is an array.
Comment #6
aprice42 commentedComment #7
xenophyle commented