Darksquallleon
New Member
Should have asked someone this a long time ago.What is the best way to use other classes within another class?For instance, lets say I have an application class:\[code\]class Application{ public function displayVar() { echo 'hello world'; }}\[/code\]and a database class\[code\]class Database{ // connects to db on construct public function query() { // queries db }}\[/code\]now, i want to add a function to my application class that uses a function from the db class\[code\]class Application{ public function displayVar() { echo 'hello world'; } public function getVar() { global $db; $sql = foo; $db->query($sql); }}\[/code\]so then I have\[code\]$db = new Database();$app = new Application();$app->getVar('var');\[/code\]Is there a better way of doing this? Really what I am looking for is the standard way of doing it, not another way of rigging it.