Jack Ellis
12-07-2010, 08:55 PM
At the moment I have a init.php file which creates the database and template objects.
So basically it sets like $db = new db; on init.php and init.php is included on every page.
Then if I want to use $db in a class, I just use global $db; to get access to it.
Why would I use the singleton pattern when I can just do it how it does it now?
Global variables are bad, yes, but any other reasons?
So basically it sets like $db = new db; on init.php and init.php is included on every page.
Then if I want to use $db in a class, I just use global $db; to get access to it.
Why would I use the singleton pattern when I can just do it how it does it now?
Global variables are bad, yes, but any other reasons?