davarravad / UserApplePie

UserApplePie website portal based on UserCake. UserApplePie is a fully open source user management system. UAP v.2 Build Started - Check that Repo.
http://www.userapplepie.com
GNU General Public License v2.0
1 stars 1 forks source link

Not needed use of global #30

Open ddmler opened 8 years ago

ddmler commented 8 years ago

For example in: UserApplePie/pages/profile.php is: global $mysqli; However since we are not in an function definition, the variable $mysqli is already in the scope. (It was declared before by the including script.) Therefore the global call is not needed. The only "useful" use case of the global keyword is in an function definition.

And for classes like in: UserApplePie/external/class.newuser.php a better way of giving a class something this class depends on is via dependency injection, instead of using global. This is considered a standard way of handling this problem. You inject a mysqli instance in the constructor and save it as an class property for later use. Again no global needed (bad practice)

davarravad commented 8 years ago

Thank You for pointing that out! I am sure I have a few bad habits that I need to clean out of the build. lol

I appreciate your input and advice!