chiprivers Posted June 5, 2012 Share Posted June 5, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/263712-accessing-parent-properties-in-extended-class/ Share on other sites More sharing options...
chiprivers Posted June 5, 2012 Author Share Posted June 5, 2012 Sorted I was using private instead of protected on my properties. I said I was new Quote Link to comment https://forums.phpfreaks.com/topic/263712-accessing-parent-properties-in-extended-class/#findComment-1351420 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.