Page 1 of 1

[SOLVED] OO syntax problem?

Posted: Sat Sep 11, 2004 1:18 pm
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? :)

Posted: Sat Sep 11, 2004 1:42 pm
by feyd
what does this say?

Code: Select all

var_export(gettype($this->db));

Posted: Sat Sep 11, 2004 5:42 pm
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 
    }
}