JoeyH3 Posted July 10, 2014 Share Posted July 10, 2014 I'm trying to teach myself OOP PHP, and I've been looking up a number of tutorials on how to to make OOP MVC frameworks. I came across this one (cached version - their site is down at the moment of posting), and noticed something interesting about it that I've not seen in other tutorials. Basically, it creates a registry class as $registry (which just uses the __set and __get functions to populate an initially empty array), and then stores variables in there. After that, $registry is passed on to the other classes via their __construct functions, so that they can access site-wide variables. I think I understand how it's working, and see how it can be used, but this tutorial is the only time I've found such a thing. I was wondering, is using such a class good practice, or how should I store and access globally needed variables (like configuration, database connections, etc)? Link to comment https://forums.phpfreaks.com/topic/289701-are-registry-classes-good-practice/ Share on other sites More sharing options...
trq Posted July 11, 2014 Share Posted July 11, 2014 As long as this registry is injected via __constructs I don't see it as such a bad thing. It is basically a IoC container in that case. Just make sure that you are type hinting to a well defined interface for this Registry. The registry pattern has the potential to cause issue when you make it a singleton that has a static getInstance() method or similar. Link to comment https://forums.phpfreaks.com/topic/289701-are-registry-classes-good-practice/#findComment-1484623 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.