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

WordPress Trac noreply at wordpress.org
Wed Aug 31 03:45:03 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 jacobsantos):

 In relation to 37699-version.2.diff, there are several problems that
 should be addressed.
  1. If `$wp_version` is not going to change, then it should be a constant.
  1. Registry patterns in OOP are meant to store objects. Using them to
 store arbitrary data does nothing that `global` does not already do.
  It is an hackish approach, but compare
 https://github.com/MimicCMS/Mimic.Experimental/tree/master/src/Storage and
 https://github.com/MimicCMS/Mimic.Experimental/blob/master/src/Application.php
 or a better implementation in https://github.com/thephpleague/container.
  1. Thinking about globals and removing them for the sake of removing
 them, is not thinking of improving the WordPress architecture. You end up
 with the mess like `WP_Customize_Manager`. Refactoring is hard, because
 you have to think about the relationships between the code and how best to
 improve the code for the long term. The WP_Container, might be a short
 term solution, until something better comes along, but the question is
 when would the better solution be developed and which intermediate steps
 will be take to incrementally improve the code from Globals to
 WP_Container to ???. #32468 was meant for safely storing objects with
 retrieval in the development vein of `MimicCMS/Mimic.Experimental`.

 It seems like this is already the direction WordPress will be going. I
 would recommend looking at Pimple or The PHP League Container
 implementation, if you are looking for inspiration for a PHP5.2
 implementation. The PHP League seems to be the most basic implementation.
 There also exists a Zend Framework implementation.

 At the very least, I would recommend using an interface, so that the
 WordPress implementation could be replaced with Pimple or The PHP League
 Container or another custom solution. You may look at my MimicCMS
 implementation for an example of how that would work.

 As an aside, the experimental code isn't that bad. Doesn't go into the
 depths that service locator libraries do, but it wasn't meant to go to
 that level. I always expect my old code to be shit, but I am surprised
 when it isn't completely terrible. Not sure if that means I'm not learning
 enough.

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


More information about the wp-trac mailing list