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

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

 Sorry for writing multiple messages, but every time I click send, a new
 thought crosses my mind.

 When evaluating whether interfaces are feasible, it should be noted that
 the current class name (`wpdb`) would be ideal as the first level of
 interface migration.

 So, I would recommend starting by creating an interface `wpdb`, and rename
 the current existing concrete implementation to `MySQLwpdb implements
 wpdb`. In this way, we have introduced an interface that can be used for
 typehinting, while not breaking any existing `instanceof` checks.

 Once namespaces are available, I would recommend adding another layer:
 `interface wpdb;`
 `interface WP\Database extends wpdb;`
 `class WP\MySQLDatabase implements WP\Database;`

 The `WP\MySQLDatabase` would still pass the `$wpdb instanceof wpdb`
 checks.

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


More information about the wp-trac mailing list