Xavier Vidal Posted January 15, 2009 Share Posted January 15, 2009 HiWe're doing some research with Prestashop in order to test if it can be our future ecommerce site.Looking through the source code i've noticed a lot of "global" keyword use. I suggest to do not use the global approach and use some singleton registry object, so instead of:global $smarty;...we can do:$smarty = Registry::get('smarty');As you can know, using "global" is not encouraged. Link to comment Share on other sites More sharing options...
Matthieu Biart Posted January 15, 2009 Share Posted January 15, 2009 Hi Xavier,The global problem you're talking about seems very interesting, but for what I know about the "Registry" class it would be to heavy for the use we'll need.But implementing a static variable inside the PrestaShop core which could be a reference to our smarty object looks like a really good idea.We keep it in mind for futur versions. Link to comment Share on other sites More sharing options...
Damien Metzger Posted January 15, 2009 Share Posted January 15, 2009 We do use a singleton for the database, and from what I see it takes 0.4ms for the 150 calls in the index.So we could, but it does not really change anything.And, by the way, it's would only be "hidden" global, that's not really cleaner. Link to comment Share on other sites More sharing options...
Xavier Vidal Posted January 15, 2009 Author Share Posted January 15, 2009 We're not talking only about performance, but about reading code more easily.The solution with static vars inside Prestashop core seems more easy to do, as there are some objects that need to be ready to access everywhere.Your software is using OOP, templates and a good architecture. "Global" keyword is an older solution, keep it away please if you can Thanks for your replies ! Link to comment Share on other sites More sharing options...
Recommended Posts