| re: Using object in function
Janwillem Borleffs wrote:[color=blue]
> Sjaakie wrote:
>[color=green]
>>PHP throws 'Fatal error: Call to a member function on a non-object ..
>>functions.inc.php on line 6' at me whenever I request this page.
>>Code at line 6: $rsContacts = $oDb->db_query($sql);
>>My best guess is the function doesn't inherit $oDb. Tried defining
>>$oDb as global, without success.
>>What am I doing wrong?
>>[/color]
>
>
> It is possible that the logics in the functions.inc.php file rely on the
> object being created already. When this is the case, you should create the
> instance before you include the file. BTW, when you say that you have tried
> to globalize $oDb, did you mean the following?
>
> function genContactList() {
> global $oDb;
> // Do Stuff
> }
>
>[/color]
Creating instance before including doesn't solve the issue.
I thought 'global $oDb;' would define $oDb as a global var, your method
solved the problem! Thanks! |