tags:

views:

106

answers:

2

Hi,

I would appreciate help from anyone who has delt with a similar problem as below...

I have a web application that runs perfectly on localhost and on my external server. I have recently uploaded it to a clients server and now receive this message:

"Call to a member function on a non-object"

The php versions are both > 5.2

Any help would be appreciated.

+1  A: 

Most likely the object did not properly initialize and has becoming something like NULL and you're trying to invoke it, possibly due to a small discrepancy in the environments. Can you post the relevant code? It would help var_dumping on the variable that's referenced in the line # ( usually the line before the line # reported ).

meder
+1  A: 

It may be that you did not make the object an instance of the class.

You need to (where ThisClass is an example class):

$obj = new ThisClass();

before you can use the $obj to call member methods/functions like this: $obj->funcA();.

Several topics on this:

http://www.codeguru.com/forum/showthread.php?t=319571

For this forum thread, it's about the constructor. In PHP, the constructor is actually

function __construct(){

}

not the Java or C# function ThisClass(){}

and on SO:

http://stackoverflow.com/questions/54566/call-to-a-member-function-on-a-non-object
http://stackoverflow.com/questions/254291/call-to-a-member-function-on-a-non-object

thephpdeveloper
Hi, Thanks for the reply. I'm well aware of this - the classes are written correctly and work perfectly on localhost and on my own external server. The error occurrs when run on a different server. Have you experienced this error when migrating to a different server?
Angus