unsubscribe
On September 5, 2018 at 2:49 AM Tony Marston <TonyMarston@xxxxxxxxxxx> wrote:
"Jeffry Killen" wrote in message
news:1258AF76-BD0A-428A-973B-E4DC22C649DE@xxxxxxxxxxx...
>
>Hello;
>
>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?
>
>I have a hard copy text* on PHP that addresses the singleton
>and factory pattern, but I have not been able to completely
>comprehend either of these.
>
>*I don't have immediate access to the book and don't remember
>the title, but the publisher is Friends of Ed / (Apress).
>
>I have been further thrown off by the use of singleton
>to refer to an object literal in _javascript_.
>
>I realize that this in not about _javascript_ but the concept
>and this use of the term has me confused.
>
>More than one object literal can be created and subsequently
>cloned by code, so how is it a singleton, in the general sense?
>
>Thank you for time and attention.
>
>JK
There is more than one way to implement a singleton. Take a look at
http://www.tonymarston.net/php-mysql/singleton.html
--
Tony Marston