To implement a central storage for objects often used throughout the application, is typically implemented using an abstract class with only static methods (or using the Singleton pattern). Remember that this introduces global state, which should be avoided at all times! Instead implement it using Dependency Injection!
- Zend Framework 1:
Zend_Registryholds the application's logger object, front controller etc.
- Yii Framework:
CWebApplicationholds all the application components, such as
You can also find this code on GitHub
.. literalinclude:: Registry.php :language: php :linenos:
.. literalinclude:: Tests/RegistryTest.php :language: php :linenos: