Re: singleton in php?
| From: | Christoph M. Becker | Date: | Wed, 05 Sep 2018 10:26:18 +0000 |
| Subject: | Re: singleton in php? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-326538@lists.php.net to get a copy of this message | ||
On 02.09.2018 at 22:15, Jeffry Killen wrote:
> I have been trying to get a better understanding of "singleton".
>
> It is defined as a class that can only produce one instance of
> itself.
>
> In the online explanation, that is accomplished by a
> private constructor function that produces an instance
> of the class within its instance.
>
> But in php I am of the understanding that a constructor
> function has to be made public and can't return anything.
>
> Here is the online reference I am looking at:
> https://www.techopedia.com/definition/15830/singleton
>
> So, at some point it seems that the class instance has to
> be exported via a return statement at some point, otherwise
> how would it be used in other code?
>
> Is there a part of the manual that addresses this?
There has been a manual page about OOP design patterns[1], but it has
been removed from the PHP manual (IMO, rightly so, since this is out of
scope). Nonetheless, the part about singletons might still be worth
reading.
[1]
<http://svn.php.net/viewvc/phpdoc/en/trunk/language/oop5/patterns.xml?revision=313136&view=markup&pathrev=331456>
--
Christoph M. Becker