I already asked this question about sessions and got a surprising and useful answer, so I'm wondering if there are any unforeseen issues about HTTP Request.
It makes sense to me to make my HTTP_Request object a singleton because it is basically a wrapper for some of php's superglobals. I can't see needing more than one instance of this EVER, and it needs no constructor arguments... which makes it even EASIER to make a singleton. Am I wrong again?
HTTP Request Class - Singleton?
Moderator: General Moderators
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
I already use a registry - the singleton registry. What's the point of having a registry that is not a singleton?, or in other words: what's the point of having 2 registered objects which are equal (note that I said equal, not identical)?feyd wrote:I avoid singletons more often than not. Why? They're difficult to (unit) test, and it's just a glorified global. If think you need a singleton, consider placing it in a Registry/Service Locator first.
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
There are situations where you might need multiple instances of the same class processing different things. It really depends on what you register and how your registry handles what you register.Oren wrote:I already use a registry - the singleton registry. What's the point of having a registry that is not a singleton?, or in other words: what's the point of having 2 registered objects which are equal (note that I said equal, not identical)?
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Given your description, neither your Registry nor the objects it creates necessarily are Singletons. A Singleton is a class where every instance shares the same properties. That is not the same as a class that creates unique instances of classes.Oren wrote:I already use a registry - the singleton registry. What's the point of having a registry that is not a singleton?, or in other words: what's the point of having 2 registered objects which are equal (note that I said equal, not identical)?
(#10850)
First of all, read my previous post
Second, all I said was: I use the Singleton Registry
I never said that the objects I register are themselves singletons.
Second, all I said was: I use the Singleton Registry
I never said that the objects I register are themselves singletons.
point taken.