Jump to content

Global in PHP


Recommended Posts

Hi

We'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

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

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 :P

Thanks for your replies !

Link to comment
Share on other sites

×
×
  • Create New...