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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.