0

This is a common error, I'm sure, but I can't figure out why I'm getting it. I'm new to OOP, but I figure I'm instantiating the object incorrectly?

First the include:

<?php include("/classes/justgiving.php"); ?>

Which is absolutely correct, as far I can tell.

Then I try to instantiate...

$justgiving = new JustGiving();

And then when I try to run the method in the object:

$justgiving->createAccount($xml);

And in the class .php file:

class JustGiving{

  function createAccount($xml) {

  // function code

  }
}

But I'm getting the following error:

Fatal error: Call to a member function createAccount() on a non-object

I have a feeling this is a real newb error, and it's something really obvious.

Thanks a lot.

tereško
  • 58,060
  • 25
  • 98
  • 150
Chuck Le Butt
  • 47,570
  • 62
  • 203
  • 289
  • please check whether include path is correct? – Muthu Kumaran Apr 09 '11 at 17:27
  • I hope you have your class inside of php () tags. Otherwise it's just text and therefore php hasn't defined your class. –  Apr 09 '11 at 17:36
  • 2
    Everything seems to be fine (proof: http://ideone.com/LMkkl ). Please post your entire code. – Crozin Apr 09 '11 at 17:46
  • Yes, good point. It turns out I was making the silly mistake of instantiating the object from outside of the function where I was calling it. `*facepalm*` – Chuck Le Butt Apr 09 '11 at 18:11

1 Answers1

0

Hmm.. what you have written seems like it should work. Maybe your problem is elsewhere?

The only reason I can think of for getting this error would be that you're trying to call a method before initializing the object, e.g.

$justgiving->createAccount($xml);
$justgiving = new JustGiving();
Eric Conner
  • 10,422
  • 6
  • 51
  • 67