Just wanted to ask people about this.
I have 5 or 6 different classes that access to the same database. So they all have a database class instanciated within their constructor and it is stored in their property so that it can access to the database in the methods.
But when they all come together in the same page, I think it's a waste of resources since they all use the same databse class but they all have their own database class instanciated within their constructor (so there are duplicates).
So is it better to just instanciate one db class and pass it by reference when other classes are instanciated so you don't waste the resources??
For example,
$size = new size(); // inside, it instanciate db class
$color = new color(); // inside, it instanciate db class
$type = new type(); // inside, it instanciate db class
Instead of above, do the following:
$db = new database();
$size = new size($db);
$color = new color($db);
$type = new type($db);
...
...
I think the second one is better but what do you think??