Troubleshooting – Warning: Invalid Argument Supplied for foreach() in Magento

bugerrorextensionsmagento-1.8

We are having a log build up of errors starting with the title error:

2017-07-12T16:32:09+00:00 ERR (3): Warning: Invalid argument supplied for foreach() in /chroot/home/apollode/apollooutlet.com/html/app/code/local/Mage/Core/Model/Config.php on line 870

2017-07-12T16:32:10+00:00 ERR (3): Notice: Undefined index: Enterprise_Search in /chroot/home/apollode/apollooutlet.com/html/app/code/local/Mage/Core/Model/Config.php on line 851

2017-07-12T16:32:10+00:00 ERR (3): Warning: array_merge(): Argument #2 is not an array in /chroot/home/apollode/apollooutlet.com/html/app/code/local/Mage/Core/Model/Config.php on line 851

2017-07-12T16:32:10+00:00 ERR (3): Warning: array_merge(): Argument #1 is not an array in /chroot/home/apollode/apollooutlet.com/html/app/code/local/Mage/Core/Model/Config.php on line 851

Looking in the Config.php file at 870 returns this code

protected function _sortModuleDepends($modules)
{
    foreach ($modules as $moduleName => $moduleProps) {
        $depends = $moduleProps['depends'];
        foreach ($moduleProps['depends'] as $depend => $true) {
            if ($moduleProps['active'] && ((!isset($modules[$depend])) || empty($modules[$depend]['active']))) {
                Mage::throwException(
                    Mage::helper('core')->__('Module "%1$s" requires module "%2$s".', $moduleName, $depend)
                );
            }
            $depends = array_merge($depends, $modules[$depend]['depends']);
        }
        $modules[$moduleName]['depends'] = $depends;
    }
    $modules = array_values($modules);

    $size = count($modules) - 1;
    for ($i = $size; $i >= 0; $i--) {
        for ($j = $size; $i < $j; $j--) {
            if (isset($modules[$i]['depends'][$modules[$j]['module']])) {
                $value       = $modules[$i];
                $modules[$i] = $modules[$j];
                $modules[$j] = $value;
            }
        }
    }

    $definedModules = array();
    foreach ($modules as $moduleProp) {
        foreach ($moduleProp['depends'] as $dependModule => $true) {
            if (!isset($definedModules[$dependModule])) {
                Mage::throwException(
                    Mage::helper('core')->__('Module "%1$s" cannot depend on "%2$s".', $moduleProp['module'], $dependModule)
                );
            }
        }
        $definedModules[$moduleProp['module']] = true;
    }

What could be causing this issue? Is this a known issue with Magento? Please help.

Best Answer

I've taken a look at the code in question and indeed this looks like an issue with Magento, but it only occurs on a specific edge case:

  1. Module X requires another module Y
  2. Module Y is not installed
  3. Module X is not active

Since you usually do not install modules that require other modules without those other modules, and the site does not crash, only logs errors, this bug has been undiscovered yet (or not cared about enough).

You will find, that you have an extension with a file in app/etc/modules like this:

<modules>
    <XXX>
        <active>false</active>
        <codePool>community</codePool>
        <depends>
            <Enterprise_Search />
        </depends>
    </XXX>
</modules>

Remove that file, or the entire module if possible. It requires the Magento Enterprise Edition, which you apparently do not have.

Related Topic