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 15:10

On Nov 14, 9:25 am, ZeldorBlat <zeldorb...@gmail.com> wrote:
>
> That's expected. Remember that in PHP each request is independent of
> the next. You'll only create one instance of your class /per request/
> but it will be available everywhere you go.
>
> Consider a database connection as an example. You open the connection
> once per request, and you close it when the request is finished.
> While the request is executing you only have/need a single connection
> (i.e. you don't need to reconnect every time you execute a query) no
> matter where in your code you go.
>
> 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? I could assign a new instance to a
variable and just reference that variable through the life of the
request. In the case of my (xml-based) config, I have to read the
config on every single request. I was hoping to avoid that without
using flat files or the session scope.

Am I missing another fundamental advantage of a singleton?

Thanks.

 

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

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