[wp-trac] [WordPress Trac] #37699: Death to Globals Episode #1: A Registry, A Pattern

WordPress Trac noreply at wordpress.org
Thu Sep 8 18:56:07 UTC 2016


#37699: Death to Globals Episode #1: A Registry, A Pattern
----------------------------+------------------
 Reporter:  wonderboymusic  |       Owner:
     Type:  enhancement     |      Status:  new
 Priority:  normal          |   Milestone:  4.7
Component:  General         |     Version:
 Severity:  normal          |  Resolution:
 Keywords:                  |     Focuses:
----------------------------+------------------

Comment (by GaryJ):

 Replying to [comment:85 dd32]:

 > A reference to a global, verses a direct global import is ultimately the
 same object, sure, you're accessing it differently, you're creating an
 extra memory reference to it, but it's still a global object which you're
 pulling in to every function you use it within.

 I think there may actually be a change (desired or not) in behaviour here.

 With the `global $wpdb` in each method, you import the latest state of
 `$wpdb` when the method is called.

 With the global being assigned to the class property in the constructor,
 you pull in the state at the time the class is instantiated. If the global
 has been changed between the constructor being called and a method being
 called, I don't think the method will see that, as it still has `$wpdb`
 from the earlier state.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/37699#comment:87>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list