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

WordPress Trac noreply at wordpress.org
Thu Sep 1 04:26:45 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):

 Replying to [comment:59 MikeSchinkel]:
 > As far as I know there is no conflict here.  You can have a `WP` class
 and a `WP` namespace and they won't conflict.

 No, there's no technical conflict, but we might want to plan for
 conventions ahead of time and avoid confusion.

 > Please don't.  Let's not start adding lots of positional parameters to
 constructors so that in the future we have to  end up writing code like
 this:
 >
 > {{{#!php
 > $query = new WP_Comment_Query(array(...), null, null, null, null, null,
 null, null, null, new FooBar() );
 > }}}

 With the above example, most people will not need to write any code like
 this, because of the poka-yoke that makes the most used case the default
 anyway. But it opens up the possibility to do so, for unit tests, for
 dependency injection or more advanced scenarios.

 Typing characters is cheap. Rewriting an architecture because it misses an
 extensibility point is not.

 > [...] so that to code for WordPress requires us to remember which
 classes we need to be able to call the methods we need [...]

 ...that's what we do as developers! (well, unless we avoid classes and
 stuck everything in global namespace, which is "probably a good idea")

 > There are better ways to handle this to create a much more usable "api",
 IMO. Everything can route through the `WP` class using helper classes
 where the methods are called using `__callStatic()`.

 I consider this to be a hack.

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


More information about the wp-trac mailing list