Re: Singletons

From: Date: Mon, 20 Oct 2008 20:06:07 +0000
Subject: Re: Singletons
References: 1 2 3 4  Groups: php.general 
Request: Send a blank email to php-general+get-282145@lists.php.net to get a copy of this message
> There is absolutely nothing in PHP which prevents you from implementing the > singleton pattern. It does if the constructor must be public. > but your attempt is doomed to failure. What makes you think that a singleton > class has to inherit from another class? Nothing at all. Except that in my particular case, I do need to inherit from another class which has a public constructor. And the class I'm trying to write needs to be a singleton. I guess that teaches me not to post a question without including a doctoral thesis about what it is I'm trying to do. I figured just including the most base and/or basic parts of what I was dealing with would be sufficient. Though, I will say I probably shouldn't have included all of that junk in the constructor in my OP. That was just a hail-mary-pray-it-might-be-a-workable-workround on my part. I was pretty sure it wouldn't be, but *shrug* > Why can't it be a separate class, In general, it can. In my case, it can't. Not unless I want to completely duplicate an already existing class. > or even a separate method in an existing class? If you use a static method > then the activities of the constructor are irrelevant. They aren't irrelevant if the class can be instantiated directly. That sort of kind of breaks the whole singleton thing... thnx, Christoph

« previous php.general (#282145) next »