[SOLVED] OO syntax problem?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

[SOLVED] OO syntax problem?

Post by timvw »

Code: Select all

class ADODB_Data extends Data
{
    var $db;

    function ADODB_Data()
    {
        $this->db =& NewADOConnection(FRAMEWORK_DATA_DSN) or
 trigger_error('Failed to connect to database.', E_USER_ERROR);
        $this->db->SetFetchMode(ADODB_FETCH_ASSOC);
    }

  function get($pairs)
    {
        $result = $this->db->Execute('select foo from bar');
     }
Fatal error: Call to a member function Execute() on a non-object

What am i doing wrong? :)
Last edited by timvw on Sat Sep 11, 2004 5:43 pm, edited 1 time in total.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

what does this say?

Code: Select all

var_export(gettype($this->db));
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

It returned NULL.

So i started thinking, and the real problem was with that subclasses (unlike java) don't call implicit the constructor of their parent class.

meaning: class Users extends ADODB_Data has it's own constructor, which does not instantiate the $this->db object and therefor said null

Code: Select all

class users extends ADODB_Data
{
    function users()
    {   
        parent::ADODB_Data(); // call parent constructor 
    }
}
Post Reply