Jump to content

accessing parent properties in extended class


chiprivers

Recommended Posts

I am tackling my first major PHP application using OOP and I am getting a little stuck with extending classes.  I want to be able to create a parent class which contains a number of properties and methods, and be able to extend this class with the ability to access the parent properties and methods.  The specific problem I am having at the moment is with a property holding a MySQL connection.

 

ie.

class DatabaseManager {

  private $mysqli;

  public function DatabaseManager() {

    $this->mysqli = new mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_DATABASE);

  }

  // various generic database methods declared here

}

class AnotherClass extends DatabaseManager {

  public function AnotherClass() {

    $this->DatabaseManager();

  }

  public function methodUsingMysqli($query) {

    $result = $this->mysqli->prepare($query);

    // do something with result blah blah

  }

}

 

When I try an run my application using the above construct and trying to access the $mysqli property declared in the parent class, it says that it does not exist.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.