I also have a class 'db' which is a database abstraction class.
The 'dad' and 'junior' classes will be called from scripts which may or may not be using the db abstraction class so I can't assume that I will be passed this class.
So whats the best way to even do this? Is just passing it to the constructor good? What if I pass it by reference (thats what I think is best). Is there another way to make the 'db' class accessible to everyone? I dont want to automatically build a 'db' class in everyone of these, because it will create a lot of overhead.
is it right to do something like this:
Code: Select all
<?php
class dad
{
var $db;
function dad(&$thisDB)
{
if(!is_object($thisDB))
{
include(db.class.php)
$this->db = new db($connectinfo)
}
else
$this->db = $thisDB
}
}
?>