Page 1 of 1

Invalid argument supplied for foreach()

Posted: Tue Dec 22, 2009 7:08 am
by AliJ
Hello,
I'm having a bit of trouble installing my vBulletin Forum, version 4.0 Beta 5.
I get this error on step 13 when it's "Updating style information for each style".

Warning:Invalid argument supplied for foreach() in /home/alij/public_html/includes/adminfunctions_template.php on line 2798."
And I can continue to the next step but when I finish the installation it won't actually show my forum.

Here is the code it's where it's saying the problem is: (Line 23) (Also this is not the full code, too big to put here)

Code: Select all

// ########################################### ##################################
/**
* Builds the stylecache and saves it into the datastore
*
* @return   array   $stylecache
*/
function build_style_datastore()
{
    global $stylecache, $vbulletin;
 
    if (!is_array($stylecache))
    {
        cache_styles();
        // this should not ever be needed unless the user has edited the database
        if (STYLECOUNT != sizeof($stylecache))
        {
            trigger_error('Invalid row in the style table', E_USER_ERROR);
        }
    }
 
    $localstylecache = array();
 
    foreach ($stylecache AS $styleid => $style) //*THIS IS THE LINE WHERE THE PROBLEM IS*
    {
        $localstyle = array();
        $localstyle['styleid'] = $style['styleid'];
        $localstyle['title'] = $style['title'];
        $localstyle['parentid'] = $style['parentid'];
        $localstyle['displayorder'] = $style['displayorder'];
        $localstyle['userselect'] = $style['userselect'];
 
        ($hook = vBulletinHook::fetch_hook('admin_style_datastore')) ? eval($hook) : false;
 
        $datastorecache["$localstyle[parentid]"]["$localstyle[displayorder]"][] = $localstyle;
    }
 
    build_datastore('stylecache', serialize($datastorecache), 1);
 
    return $datastorecache;
}
Any help is always appreciated.
Thank you,

Ali J.

Re: Invalid argument supplied for foreach()

Posted: Tue Dec 22, 2009 7:58 am
by MichaelR
$stylecache isn't being defined as an array. And your if (!is_array($stylecache)) { } block doesn't prevent the foreach loop from running if it isn't an array. It triggers an error and then performs the loop anyway. And your foreach loop redefines $localstylecache each time, so the elements from the previous loop(s) are being overwritten.

Re: Invalid argument supplied for foreach()

Posted: Tue Dec 22, 2009 8:34 am
by AliJ
Okay,
Thanks, I fixed it.