I have an includes.php page that I load at the top of every page of my website. When I design a website, the number of classes I use is growing. So I get something like this:
$db = new DB($config);
$login = new Login($db, $config);
$form = new Form($db, $config);
And the list goes on and on. I have two questions about this practice:
Firstly, given that I cannot use a class on a specific page (I may not have a $ form on every single page), how important is it to deal with loading this class every time any given page is loaded?
Secondly, you may have noticed that I am passing an instance of the $ db class to all other classes, as well as the $ config variable. In the php code of each class, I am doing something like this:
public $db;
public $config;
public function __construct($db, $config, $smarty){
$this->db = $db;
$this->config = $config;
}
'this' :
public function myfunction(){
$this->db;
$this->config;
}
'extends', $db , db? $db - ?
!