Using global variables is generally considered unwise for large applications as it introduces coupling
between modules and it is very difficult to track down where and when a given global variable is modified during the processing of a script. The solution is to pass variables as parameters through functions to where the data is required. However, this causes a problem in that you can end up with lots of “pass-through” parameters which clutter up function signatures for functions that do not use the data, except to pass it on to the next function.
One solution to this is to consolidate the storage of such data into a single object which is easy to find; this is known as the registry. As its name implies, Zend_Registry implements the Registry design pattern and so is a handy place to store objects that are required in different parts of the application .
Zend_Registry::set() is used to register to objects with the registry. Internally, the registry is implemented as an associative array and so when you register an object with it, you have to supply the key name that you want to identify it with. To retrieve the object at a different place in the code, Zend_Registry::get() is used, where you supply the key name and a reference to the object is returned. There is also a helper function Zend_Registry::isRegistered() which enables you to check if a given object key is registered or now.
between modules and it is very difficult to track down where and when a given global variable is modified during the processing of a script. The solution is to pass variables as parameters through functions to where the data is required. However, this causes a problem in that you can end up with lots of “pass-through” parameters which clutter up function signatures for functions that do not use the data, except to pass it on to the next function.
One solution to this is to consolidate the storage of such data into a single object which is easy to find; this is known as the registry. As its name implies, Zend_Registry implements the Registry design pattern and so is a handy place to store objects that are required in different parts of the application .
Zend_Registry::set() is used to register to objects with the registry. Internally, the registry is implemented as an associative array and so when you register an object with it, you have to supply the key name that you want to identify it with. To retrieve the object at a different place in the code, Zend_Registry::get() is used, where you supply the key name and a reference to the object is returned. There is also a helper function Zend_Registry::isRegistered() which enables you to check if a given object key is registered or now.