View Single Post
05-06-2008, 04:27 PM
is cute and cuddly
Join Date: Mar 2008
Location: Vegas, Baby
The basic premise is that you have a static instance of the object, with a method to help you obtain that static instance. This way, once the object is loaded for the first time in your page, you can then call it by reference anywhere else in the page, including from inside other objects, and it will always return a reference to the same instance. This way any properties of the object being called will remain the same (static) from the time you first call it, till the end of the script execution. At least that's what I understand of it.
The method of doing it, that's apparently a little more up for debate than I originally suspected.
The Singleton Design Pattern for PHP
illustrates a few ways, one of which also seems to be synonymous with the above mentioned registry pattern.
Whichever method you choose to go with, the singleton, or the singleton registry, I personally think both have their merits. This could be from a novice point of view however, as the more I study, the more I come across people who are (self proclaimed at least) experts crying the woes of the singleton because of how it resembles a global. I've read claims on how you should avoid this at all costs, but I've come to ignore them a bit since A) it works great for me, and B) if Zend Framework incorporates singletons, despite my dislike of frameworks, I'm sure it's not that evil.
View Public Profile
Send a private message to delayedinsanity
Visit delayedinsanity's homepage!
Find More Posts by delayedinsanity