|
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]
|