Re: Singletons
| From: | Stut | Date: | Mon, 20 Oct 2008 19:38:07 +0000 |
| Subject: | Re: Singletons | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-282142@lists.php.net to get a copy of this message | ||
On 20 Oct 2008, at 20:24, Christoph Boget wrote:
Correct, but you're then breaking one of the rules of the singleton pattern. If you're stuck with that then you'll need to enforce the singleton aspect in non-technical ways (policy, regular beatings, etc).The problem being if the class in question derives from another class that has a public constructor... If you are in that particular situation (which I am), you're basically SOL and the statement above has no bearing.public function __construct()A singleton would usually have a private constructor to prevent non-singleton instances.
Not really, not if you do it correctly. As far as I can tell, apart from getting it completely wrong (it would have been wrong in all languages I can think of) the only issue you've come across is not being able to extend a class with a public constructor. If that's the only issue you can find then I don't see much to be desired. I don't know the exact reason for this limitation but I'm sure there's a good one. The core PHP devs don't make a habit of enforcing arbitrary limitations like that. If you think it's worth fixing feel free to report it as a bug at http://bugs.php.net/ and you'll probably get told the reason it's like that. -Stut -- http://stut.net/Singletons are not rocket science, but as with all patterns you really need to understand the theory before trying to implement and use it.Agreed. But apparently implementing them in PHP leaves things to be desired.