[wp-trac] [WordPress Trac] #23016: Allow plugins to manipulate WP_Roles ($wp_roles global) on construct

WordPress Trac noreply at wordpress.org
Thu Nov 3 03:19:04 UTC 2016


#23016: Allow plugins to manipulate WP_Roles ($wp_roles global) on construct
-------------------------------------------------+-------------------------
 Reporter:  johnjamesjacoby                      |       Owner:  pento
     Type:  defect (bug)                         |      Status:  closed
 Priority:  normal                               |   Milestone:  4.7
Component:  Role/Capability                      |     Version:  3.5
 Severity:  normal                               |  Resolution:  fixed
 Keywords:  has-patch has-unit-tests commit      |     Focuses:
  needs-dev-note                                 |
-------------------------------------------------+-------------------------

Comment (by charliespider):

 > Did either of you run into problems in the wild with this?

 No not this specifically, but we **have** been bitten by creating local
 variables from globally scoped objects and then ended up with duplicates
 after the global was changed.

 So we basically just want to help prevent you from falling into the same
 hole we have. It's not an easy situation to fix, and one of the reasons
 why globals should be avoided like the plague.

 If PHP allowed objects to actually be immediately destroyed when you
 unset() them, then this would be easy. But unfortunately, unset objects
 just stick around, allowing any code with local copies to still access and
 use them, up until PHP needs more memory and they get garbage collected.

 The only way around it that I can think of is to use an internal property
 to mark the global object as active, and then set that to false on the old
 object when replacing the global. Then you can issue a doing_it_wrong() if
 the object is used. Pretty fugly hack, but what else can you do when
 you've already given an object global scope in a distributed product?

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


More information about the wp-trac mailing list