p<. Zend_Registry is based on a singleton that insures that only one Zend_Registry instance is used to save global data, so that you can rely on setting and retrieving initialized values throughout your application. It is the living implementation of the "Registry design pattern(Registry design pattern explained by Martin Fowler)":http://martinfowler.com/eaaCatalog/registry.html in Zend Framework. The Zend_Registry class provides methods for adding a value to the global storage (_set_), checking if an index is set (_isRegistered_) and retrieving a previously set index (_get_). But what if you want to replace a value from the global storage? p<. Zend_Registry provides no method to delete an existing index and trying to set an existing index will result in an Exception being thrown. Surely enough, you can use the _unsetInstance() method to delete all the existing data and repopulate, but that is most likely to do more harm than good. p<. The solution is very simple and it involves using the SPL ArrayObject interface methods that are implemented by Zend_Registry pre(brush: php). Zend_Registry::getInstance()->offsetUnset(‘index’);
p<. There is a reason for Zend_Registry not providing this feature. The Zend_Registry component provides a global registry to the Zend Framework, much like the $_GLOBALS array in pure PHP. The problem is that when changing values in the global registry, other parts of your application might be affected. For example if you store a cache object into the Zend_Registry and then instantiate some random class that replaces it with another value or object, you might later have a problem in another part of your application that expects the original cache reference in the Registry. p<. In conclusion, the Zend_Registry (much like the $_GLOBALS array in PHP) is a handy and quick way to store and retrieve values and objects. That being said it enables you to develop all sorts of bad coding practices and to produce code bloat. Also it makes writing effective unit tests a pain. p<. My advice to you is: *Don't be lazy!*; find a way to implement "dependency injection(Read about Dependency Injection on Wikipedia)":http://en.wikipedia.org/wiki/Dependency_injection in your classes and only pass on objects and data you actually need!