Uhkis Posted May 20, 2010 Share Posted May 20, 2010 I'm using my Database class object in an function, the function works fine in the file where the function is. If I try to include the function containing file to another file, I get error message: Call to a member function execute() on a non-object.... In the function file, I create the object ($DB = new Database(...)) and use it in a function by global $DB and so on, works fine, except when that file is included somewhere. Does PHP handle functions or objects differently when they are included in other files? Link to comment https://forums.phpfreaks.com/topic/202416-object-weirdness-in-an-included-file/ Share on other sites More sharing options...
PFMaBiSmAd Posted May 20, 2010 Share Posted May 20, 2010 Does PHP handle functions or objects differently when they are included in other files? No, unless you are including a file using a URL instead of a file system path. If you post your code, someone can probably quickly tell you why it is not working. Link to comment https://forums.phpfreaks.com/topic/202416-object-weirdness-in-an-included-file/#findComment-1061274 Share on other sites More sharing options...
Uhkis Posted May 20, 2010 Author Share Posted May 20, 2010 I guess these are the relevant lines (lots of censorship): $DB = new Database($SERVER, $LOGIN, $PASSWORD, $DATABASE); $DB->connect(); // works fine function printStuff () { global $DB; try { $query = "...."; $results = $DB->execute($query); // this is the line of problem, but only if this file is included somewhere $resultArray = $results->fetchAll(); } catch (DatabaseException $e) { } } Link to comment https://forums.phpfreaks.com/topic/202416-object-weirdness-in-an-included-file/#findComment-1061282 Share on other sites More sharing options...
PFMaBiSmAd Posted May 21, 2010 Share Posted May 21, 2010 Since that does not show how you are including the file, it will be a little hard for anyone to help with your problem. Link to comment https://forums.phpfreaks.com/topic/202416-object-weirdness-in-an-included-file/#findComment-1061437 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.