Menu

Setup started throwing Invalid argument supplied for foreach() warning

2014-10-06
2015-02-11
  • Thad Hunter

    Thad Hunter - 2014-10-06

    Encountered an error yesterday while trying to add a new class: Warning: Invalid argument supplied for foreach() in /var/www/html/itop/setup/compiler.class.inc.php on line 342

    These issues cannot be reasonably diagnosed by a user and make the application unusable.

    The error (Warning is mislabeled) hangs at the "Compiling the data model" setup step.

    The area of php code at line 342 is:

    /**
     * Helper to form a valid ZList from the array built by GetNodeAsArrayOfItems()
     */     
    protected function ArrayOfItemsToZList(&$aItems)
    {
        $aTransformed = array();
        foreach ($aItems as $key => $value)
        {
            if (is_null($value))
            {
                $aTransformed[] = $key;
            }
            else
            {
                if (is_array($value))
                {
                    $this->ArrayOfItemsToZList($value);
                }
                $aTransformed[$key] = $value;
            }
        }
        $aItems = $aTransformed;
    }
    
     
  • Leonardo Méndez

    After the line

        $aTransformed = array();
    

    I added the following:

        if (!is_array($aItems))
           return $aTransformed;
    

    Of course, it should be investigated why $aItems comes with a non array value, but after the patch, it seems to compile and work fine.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.