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

WordPress Trac noreply at wordpress.org
Mon Oct 10 07:52:11 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 dnaber-de):

 Replying to [comment:95 pento]:
 > Hiding the `$wpdb` global behind a property decreases the readability of
 the code, as well as causing irrelevant output when dumping an object.

 Increasing responsibilities of each methods increases readability? How?
 The advantage of having a dependency (like `wpdb`) in a property is, that
 you can rely on its type and existence when you use it. You don't need to
 care about whether it's in place or even how it came to place.

 What you actually do is implementing a shorthand variable. But that could
 have been done also like that:

 {{{#!php
 <?php
    public function foo() {

        $wpdb = $this->db;
        //...
    }
 }}}

 But instead you import a global variable (which could be of any type, or
 even not set) to the local scope ''in every single'' method. That's
 actually decreases readability.

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


More information about the wp-trac mailing list