Re: Singletons
| From: | Tony Marston | Date: | Mon, 20 Oct 2008 19:55:56 +0000 |
| Subject: | Re: Singletons | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-282144@lists.php.net to get a copy of this message | ||
""Christoph Boget"" <jcboget@yahoo.com> wrote in message
news:540509760810201224h4eb54e03p65bf583ff312f14d@mail.gmail.com...
>
<snip>
>
>> 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.
There is absolutely nothing in PHP which prevents you from implementing the
singleton pattern. There are several ways in which it can be done (take a
look at http://www.tonymarston.net/php-mysql/singleton.html
for an example)
but your attempt is doomed to failure. What makes you think that a singleton
class has to inherit from another class? Why can't it be a separate class,
or even a separate method in an existing class? If you use a static method
then the activities of the constructor are irrelevant.
--
Tony Marston
http://www.tonymarston.net
http://www.radicore.org