0

I have class that extends another class.

class TWITTER_FOLLOWERS extends TWITTER_BOT

in TWITTER_FOLLOWERS i want to acces the db object from TWITTER_BOT but i get just an error

Fatal error: Call to a member function fetch_all_array() on a non-object in /var/www/bot/inc/TWITTER_FOLLOWERS.php on line 163

On line 163 i have this code

$results = $this->db->fetch_all_array($q);

How can i access the parent object db ?

tereško
  • 58,060
  • 25
  • 98
  • 150
streetparade
  • 32,000
  • 37
  • 101
  • 123

3 Answers3

4

Sounds like you haven't instantiated the $db variable in the parent class. Are you using a __construct() function in your subclass? Don't forget to call parent::__construct() in there so the function isn't "overwritten". Also, is $db a protected or public variable? It'll need to be one of the two for a subclass to be able to access it. We'll need to see more code to dig deeper.

typeoneerror
  • 55,990
  • 32
  • 132
  • 223
2

did you run the parent constructor? this looks like the subclass doesn't bother initializing properly (by calling the parent constructor).

just somebody
  • 18,602
  • 6
  • 51
  • 60
1

To be honest I'm not sure what you exactly want. But my guess would be that you are looking for the parent special name.

Timo Willemsen
  • 8,717
  • 9
  • 51
  • 82
  • that was realy stupid of me, i didnt call the parent constructor after i did parent::__construct(); it fixed the error – streetparade Jan 01 '10 at 19:36