Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Jun 2009
    Location
    West Sussex
    Posts
    27
    Thanks
    0
    Thanked 4 Times in 4 Posts

    Singleton Pattern

    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?
    Last edited by Lamped; 06-05-2011 at 04:04 PM. Reason: Reverted per user request

  • #2
    New Coder
    Join Date
    Jun 2009
    Location
    West Sussex
    Posts
    27
    Thanks
    0
    Thanked 4 Times in 4 Posts
    bump for pros.

  • #3
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts
    Quote Originally Posted by Jack Ellis View Post
    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...


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •