Re: singleton in php?

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

 



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



[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