WordPress.org

Ideas

Global functions for global variables.

  1. anadgouda
    Member

    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


    getDB()->query();

    instead of


    $wpdb->query();

    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.

    Posted: 13 years ago #
  2. John Blackbourn
    Inactive

    12345

    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.

    Posted: 13 years ago #
  3. zackdesign
    Inactive

    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!

    Posted: 12 years ago #
  4. scribu
    Inactive

    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.

    Suggest closing.

    Posted: 10 years ago #
  5. Peter Westwood
    Inactive

    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.

    Posted: 10 years ago #

RSS feed for this topic

Topic Closed

This topic has been closed to new replies.

  • Rating

    12345
    81 Votes
  • Status

    Sorry, not right now