PDA

View Full Version : fatal error: ...non-object



Jake Bunce
Wed 6th Feb '02, 12:13am
i took the following code in a script and moved it into it's own function at the top of the script and then put "getmembers();" (the name of the function) in the place where the code used to be and it gave me the following error: Fatal error: Call to a member function on a non-object in /home/jake/public_html/forum/clan.php on line 15 . line 15 is the first line in the new function, starting with $users = $DB_site->query(".



$users = $DB_site->query("
SELECT DISTINCT
user.*, userfield.*, session.userid AS sessionuserid, session.lastactivity
FROM user
LEFT JOIN usergroup ON (usergroup.usergroupid = user.usergroupid)
LEFT JOIN userfield ON (userfield.userid = user.userid)
LEFT JOIN session ON (session.userid = user.userid
AND session.userid <> 0 AND user.invisible = 0 AND session.lastactivity>0)
WHERE user.usergroupid IN($clan_usergroup,$admin_usergroup,$supermod_user group,$mod_usergroup)
GROUP BY user.username
ORDER BY user.username
");

while ($user = $DB_site->fetch_array($users)) {
if ($user[usergroupid] == $clan_usergroup || $admin_usergroup || $supermod_usergroup || $mod_usergroup) {
if (($clancount++ % 2) == 0) $backcolor = "{secondaltcolor}";
else $backcolor = "{firstaltcolor}";
douserinfo();
eval("\$clanbits .= \"".gettemplate("clanbits")."\";");
}
}

unset($user);


any ideas? what is a non-object and a member function?

Mark Hensler
Wed 6th Feb '02, 2:45am
The non-object means that $DB_site is not an object. The non-member means that query() is not a member of the $DB_site object (which erred too).

Generally:
$object->member

Make sure that somewhere above that you put:
$DB_site = new Something;
I'm not very familiar with vB source, but you get the idea. You just need to create $DB_site as an object.

Jake Bunce
Wed 6th Feb '02, 3:20am
thanks. that gives me a better idea of what the problem is. the $DB_site and query() things are all defined in global.php i believe... and i have global.php required at the top of my script.

*me goes to mess with script*

RINCE
Wed 6th Feb '02, 10:05am
If you want to use the DB Class of VBulletin inside a function you have to add this to your func:



global $DB_site;

Jake Bunce
Thu 7th Feb '02, 3:25am
thank you. that fixed it. i had to make all my $vars global within the function.