Change host php error Invalid argument foreach

Hello,

I have just changed to another host and some of my cms functions are displaying the error Invalid argument supplied for foreach() on the new server. I have searched the web and the forums but I am still not sure where the problem comes from.

Some info:
The old server had php 5.3.27 and the new has php 5.3.23.
The main difference between the old and new server is that the old server used lightspeed with suPHP and the new one is using apache with fastcgi.
From the php error that I see, Invalid argument supplied for foreach(), it appears to be caused by differences in the use of htaccess and php.ini.

Has anyone else come across this problem and solved it?

Unfortunately, unless your htaccess is passing an array to your script, your script is likely the issue and your prior host was just hiding the error.

Can you paste some of the code where the error occurs?

The big question is what are you passing to foreach – a lot of the server header stuff can change between http server implementations and php mounting styles.

The code has been working for over a year now but here is one snippet.


        //Check that the directory contains an xml file
        foreach($toolDirs as $toolDir) {
            $dirName = $fmanager->PathName($toolBaseDir . $toolDir);
            $xmlFilesInDir = $fmanager->listFiles($dirName,'.xml');
            if ($xmlFilesInDir) {
                foreach($xmlFilesInDir as $xmlfile) {

                $xmlDoc = simplexml_load_file($dirName.$xmlfile, 'SimpleXMLElement');
                if (!$xmlDoc) { continue; }
                if (version_compare(PHP_VERSION, '5.1.3') >= 0) {
                    if ($xmlDoc->getName() != 'mosinstall') { continue; }
                }
                $ok = false;
                $attrs =  $xmlDoc->attributes();
                if ($attrs) {
                    if (isset($attrs['type']) && ($attrs['type'] == 'tool')) { $ok = true; }
                }
                if (!$ok) { continue; }
                
                if (isset($xmlDoc->cxlangdir)) {
                    $_xmlLangDir = trim($xmlDoc->cxlangdir);
                    if ($_xmlLangDir != '') {
                        global $alang;
                        if (file_exists($mainframe->getCfg('absolute_path').$_xmlLangDir.'/'.$alang.'.php')) {
                            require_once($mainframe->getCfg('absolute_path').$_xmlLangDir.'/'.$alang.'.php');
                        } else if (file_exists($mainframe->getCfg('absolute_path').$_xmlLangDir.'/english.php')) {
                            require_once($mainframe->getCfg('absolute_path').$_xmlLangDir.'/english.php');
                        }
                    }
                }


Okay, to begin, I’d put in some output to see what your foreach statements are getting.

Before

foreach($toolDirs as $toolDir) {

I’d put

var_dump($toolDirs);

And before

foreach($xmlFilesInDir as $xmlfile) {

I’d put

var_dump($xmlFilesInDir);

Once you see what each variable contains, that may identify the issue.

Also, IIRC some of the XML support depends on having some underlying xml packages installed on the server.

Changes between the server php extensions are what I am thinking too. I just found another difference. PDO for mysql is on the old server.
Now that you mention xml support I will have to look at that too.