Global functions for global variables.
I understand that global variables are convenient for extending WordPress. However, it is also dangerous since someone can inadvertently write into the global variable, affecting the entire system. Instead of providing access to the variables directly, can WordPress provide a set of global functions that return the variable? For example
This will not enforce but allow global variables to read from, without using the explicit global variable.
If someone wants to write into them, he/she can choose to use the explicit global variable.
I don't see how this will prevent people from inadvertently writing to the global variable, as the global variable must still exist in order to be written to when needed.
If someone writes their own plugin and is worried about inadvertently writing to the global variable, they can create their own function within the plugin to give themselves this functionality.
Global variables have been killing us when creating a certain plugin. Must be fixed! Template tags like the_title and the_content were crapping themselves out :(
And this was even when we were following recommended loop guidelines!
Because using getter functions can't be enforced, it won't solve much.
Until WP moves to PHP5-only syntax, this will remain a problem.
The globals are there for easy access to the functionality both from within plugins and within themes.
However the data is stored within the running script it has to exist in something within the global space.
Adding functions to get hold of things like the current instance of the db class don't add any benefit and just end up increasing code bloat.
RSS feed for this topic
This topic has been closed to new replies.