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

WordPress Trac noreply at wordpress.org
Wed Aug 17 22:35:14 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 schlessera):

 I just thought of another argument for introducing interfaces.

 Right now, we can't just have everything within the Registry/Service
 Locator, as there's still lots of third-party code that depends on the
 `$wpdb` global.

 Having interfaces also allows us to use the Decorator pattern, which we
 could use to elegantly show "deprecated" notices for code that still uses
 the actual global. So, the WPDB object gets instantiated, the Registry
 saves its instance, and then a `DeprecatedWPDBDecorator` gets wrapped
 around that instance, and this wrapped version gets stored as the global
 `$wpdb`. The decorator would just accept the exact same methods as the
 normal WPDB, but for each method, it would throw a deprecated notice
 before forwarding the arguments to the real method.

 This would open up a safe migration path to get people away from using the
 globals with due notice.

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


More information about the wp-trac mailing list