You are here: Re: Simple (?) Singleton Question « PHP Programming Language « IT news, forums, messages
Re: Simple (?) Singleton Question

Posted by Rob Wilkerson on 11/14/07 22:43

On Nov 14, 12:07 pm, Michael Fesser <neti...@gmx.de> wrote:
> .oO(Rob Wilkerson)
>
> >> That's how singletons work in PHP.
>
> >That's what I was afraid of. Kind of makes singletons worthless (at
> >least for my case), doesn't it?
>
> Partly. But they still assure that there's only a single instance to
> work with, which is globally available from everywhere in your scripts.

Yeah, I guess I was sort of (illogically) hoping that singletons could
also manage to defy the fundamental nature of PHP and include a level
of persistence that would allow me to perform certain operations only
once. I suppose I just don't understand the concept of "globally
available from everywhere in your scripts" if a "new" instance is
actually being created with each request. If, somewhere between
requests, I alter my config then I could have one user using an old
version (until the next request) and another user using the new one.

I'd like to have more control over when the config is read so that I
can ensure that it's the only one in play at any given time, but the
config is loaded in a pseudo front controller, so it's not like I'll
ever encounter a condition under which it *doesn't* exist. That's
something, I guess.

Part of this is academic, too. It doesn't seem like much of a
singleton if I have to keep loading it over and over and if there's no
way for me to ensure that every user of my system is using precisely
the same configuration. Instead, each user is running their own fully
independent and fully functional instance of the "singleton" and
creating a new instance on each separate request. In a distributed
architecture more complex than what I need for this project, I suppose
the singleton-like nature could come in handy when using the same
instance in multiple components, but for my project its practical use
is limited.

Thanks for all of your help, guys. At least I have a better
understanding of the PHP runtime.

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация