Re: OO and "Singleton" class

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

 



On Tue, Sep 01, 2009 at 06:06:24PM -0400, Eddie Drapkin wrote:

> On Tue, Sep 1, 2009 at 5:16 PM, Paul M Foster<paulf@xxxxxxxxxxxxxxxxx> wrote:
> >
> > I'm a little fuzzy on some of the PHP implementation details for some
> > stuff. In PHP (5 <= phpversion() < 5.3), I'd like a configuration class
> > which can only effectively be instantiated once. Will the following code
> > do this? Any other suggestions or corrections? (Code is untested. Feel
> > free to complain about syntax.)

<snip>

> 
> The primary thing you need to do to make a class a singleton is
> disallow the instantiation of a class directly.  Which means using
> visibility, which is conspicuously absent from your example above.
> 
> So, to prevent normal instantiation, we make the constructor private.
> Also, we need a method to retrieve the instance.  Static members serve
> this purpose:

Good explanation. Thanks. I'll try it out.

Paul

-- 
Paul M. Foster

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[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