Status: offline

trampoline

Forum User
Full Member
Registered: 02/24/06
Posts: 392
I get this error but only once a week or so....

An error has occurred:
2 - Invalid argument supplied for foreach() @ /Library/WebServer/commun/Documents/lib-common.php line 4723

when i load the main page of one of my sites however if i load again it goes away....????
Something must be wrong ?

Status: offline

Dirk

Site Admin
Admin
Registered: 01/12/02
Posts: 13073
Which Geeklog version is that? There's no foreach in or near line 4723 in Geeklog 1.4.1 ...

bye, Dirk

Status: offline

trampoline

Forum User
Full Member
Registered: 02/24/06
Posts: 392
1.4.1 this is the function...
Text Formatted Code
function COM_makeList( $listofitems, $classname = '' )
{
    global $_CONF;

    $list = new Template( $_CONF['path_layout'] );
    $list->set_file( array( 'list'     => 'list.thtml',
                            'listitem' => 'listitem.thtml' ));
    $list->set_var( 'site_url', $_CONF['site_url'] );
    $list->set_var( 'layout_url', $_CONF['layout_url'] );
    if( empty( $classname ))
    {
        $list->set_var( 'list_class', '' );
        $list->set_var( 'list_class_name', '' );
    }
    else
    {
        $list->set_var( 'list_class', 'class="' . $classname . '"' );
        $list->set_var( 'list_class_name', $classname );
    }

    foreach( $listofitems as $oneitem )
    {
        $list->set_var( 'list_item', $oneitem );
        $list->parse( 'list_items', 'listitem', true );
    }

    $list->parse( 'newlist', 'list', true );

    return $list->finish( $list->get_var( 'newlist' ));
}

Status: offline

Dirk

Site Admin
Admin
Registered: 01/12/02
Posts: 13073
You must have modified your lib-common.php then, since COM_makeList only starts in line 4797.

Anyway, the problem is with whatever is calling that function. Do you have some sort of dynamic block on your site that displays items in a list? Looks like occasionally, it's calling COM_makeList with an empty data set.

The function should certainly be more fault tolerant, but the real problem is the calling entity.

bye, Dirk

Status: offline

trampoline

Forum User
Full Member
Registered: 02/24/06
Posts: 392
Quote by: Dirk

You must have modified your lib-common.php then, since COM_makeList only starts in line 4797.

Anyway, the problem is with whatever is calling that function. Do you have some sort of dynamic block on your site that displays items in a list? Looks like occasionally, it's calling COM_makeList with an empty data set.

The function should certainly be more fault tolerant, but the real problem is the calling entity.

bye, Dirk



I only have

GL Menu
Forum
MyCal in blocks on front page could it be one of those ???

Status: offline

Dirk

Site Admin
Admin
Registered: 01/12/02
Posts: 13073
I've just added a
Text Formatted Code
if (is_array($listofitems)) {
in front of the foreach in CVS. I still think it's a problem in the calling entity, though. Hard to tell where it's coming from ...

bye, Dirk

Status: offline

trampoline

Forum User
Full Member
Registered: 02/24/06
Posts: 392
Thanks...I have altered as follows, is this correct ?
Text Formatted Code

if (is_array($listofitems))
    foreach( $listofitems as $oneitem )
    {
        $list->set_var( 'list_item', $oneitem );
        $list->parse( 'list_items', 'listitem', true );
    }

    $list->parse( 'newlist', 'list', true );

    return $list->finish( $list->get_var( 'newlist' ));
}

Status: offline

Dirk

Site Admin
Admin
Registered: 01/12/02
Posts: 13073
Yep.

bye, Dirk

Status: offline

trampoline

Forum User
Full Member
Registered: 02/24/06
Posts: 392
Great,
Site loads, in your example you wrote it as
Text Formatted Code
if (is_array($listofitems)) {

Which failed to load, I guess because of the opening {
so I removed the { and it loads OK
Thanks, I guess it was some odd thing but at least the error will not effect anything now..