View Full Version : Singleton Pattern

Jack Ellis
12-07-2010, 09: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?

Jack Ellis
12-08-2010, 12:12 AM
bump for pros.

12-08-2010, 02:49 AM
Edit: Screw it, it seems this section is completely dumb when it comes to anything other than basic PHP.

Aye, it's shocking how people can have the audacity to think they have personal lives to attend to instead of being in front of their computer awaiting the chance to answer any and all questions at the drop of a hat. Ignorant bastards the lot of us. Honestly, how could we not realise you came before anything else we might have to attend to...