Using object in function

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
I have this little problem I just can't figure out...
Code snippet:


include('../_include/'); // db-class
include(''); // has genContactList()
$oDb = new db;



PHP throws 'Fatal error: Call to a member function on a non-object .. 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?


Re: Using object in function

Sjaakie wrote:
Quoted text here. Click to load it

It is possible that the logics in the 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


Re: Using object in function

Janwillem Borleffs wrote:
Quoted text here. Click to load it

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!

Site Timeline