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.