Jump to content

Singleton Pattern


3raser

Recommended Posts

(example I looked at: http://develturk.com/tags/selfinstance/)

 

I've looked into the singleton pattern and a few examples. I've understood most of its concept, but I still have a few things puzzling me. I noticed that you're not supposed to allow cloning (obviously) or the construction method as it shows in an example:

 

    //this object can not copy
    //except the getInstance() method.
    private function __clone() {}
   
    //prevent directly access
    //we want acces this only from getInstance method.
    private function __construct(){}

 

Do I also have to do this for child classes, or just the parent class?

Link to comment
https://forums.phpfreaks.com/topic/259849-singleton-pattern/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.