Hey I’m wondering when accessing Zend_Registry in an application if you need to include getInstance() and if so, why?
for example
Zend_Registry::getInstance()->get('db');
vs.
Zend_Registry::get('db');
they both seem to work with the later being less verbose.
I vaguely understand that Zend_Registry is a singleton, which I think means there can only be one instance of it? so why would you need getInstance()?
I wrote the code for Zend_Registry in 2007.
You can use the static
get()andset(), and it affects the default instance of the registry, stored as a static member of the class. This is the intended usage for most situations.All the other methods of Zend_Registry are pretty much to support non-typical situations, like if you wanted to implement your own class for your registry but still make it the default singleton. Or if you want to get the actual registry object, for example so you can serialize the whole registry object with all its contents.