473,387 Members | 1,790 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Using object in function

Hi,
I have this little problem I just can't figure out...
Code snippet:

<?

include('../_include/database.inc.php'); // db-class
include('functions.inc.php'); // has genContactList()

$oDb = new db;
$oDb->db_connect();

....

genContactList();
?>

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?

Thanks!
Jul 17 '05 #1
2 1617
Sjaakie wrote:
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?


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
}
JW

Jul 17 '05 #2
Janwillem Borleffs wrote:
Sjaakie wrote:
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?

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
}


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!
Jul 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Michael Sparks | last post by:
Anyway... At Europython Guido discussed with everyone the outstanding issue with decorators and there was a clear majority in favour of having them, which was good. From where I was sitting it...
28
by: Daniel | last post by:
Hello =) I have an object which contains a method that should execute every x ms. I can use setInterval inside the object construct like this - self.setInterval('ObjectName.methodName()',...
7
by: Ireneusz SZCZESNIAK | last post by:
I want to sort a vector with the std::sort function. There are two functions: one with two arguments, the other with three arguments. I am using the one with three arguments. I noticed that...
6
by: marktm | last post by:
Hi- I am trying to use setInterval to call a method within an object and have not had any luck. I get "Object doesn't support this property or method" when I execute the following code. What I...
17
by: Danny J. Lesandrini | last post by:
The following code works with a standard MDB to navigate to a particluar record (with a DAO recordset, of course) but it's giving me problems in an ADP I'm working on. Dim rs As ADODB.Recordset...
11
by: Grasshopper | last post by:
Hi, I am automating Access reports to PDF using PDF Writer 6.0. I've created a DTS package to run the reports and schedule a job to run this DTS package. If I PC Anywhere into the server on...
19
by: Kamilche | last post by:
I have looked at many object-oriented programming frameworks out there for C. Though the ideas presented are intriguing, and I've used some of them in my own work, they all suffered some drawback...
6
by: ransoma22 | last post by:
I developing an application that receive SMS from a connected GSM handphone, e.g Siemens M55, Nokia 6230,etc through the data cable. The application(VB.NET) will receive the SMS automatically,...
14
by: B Williams | last post by:
I am stuck on an assignment that uses classes and functions. I am receiving numerous errors when I try to run a test program to see if I wrote it correctly. Can someone please point me in the right...
6
by: Murray Hopkins | last post by:
Hi. THE QUESTION: How do I get a reference to my Object when processing an event handler bound to an html element ? CONTEXT: Sorry if it is a bit long. I am developing a JS calendar tool....
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.