Re: Singletons

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 20 Oct 2008, at 20:24, Christoph Boget wrote:
 public function __construct()
A singleton would usually have a private constructor to prevent
non-singleton instances.

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.

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).

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.

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/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux