[wp-trac] [WordPress Trac] #23016: Allow plugins to manipulate WP_Roles ($wp_roles global) on construct
WordPress Trac
noreply at wordpress.org
Wed Nov 2 19:37:02 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):
@johnjamesjacoby
I think you missed the point @mnelson4 was trying to make.
Your examples seem to just be illustrating how objects are passed by
reference in PHP (ie: variables are pointers), but without addressing the
issue that $wp_roles->reinit() NOW returns a NEW object (ie: new pointer
to new object), whereas it previously returned the same object (existing
pointer to existing object).
previously:
{{{#!php
<?php
global $wp_roles; // points to object with spl_object_hash of "A" (massive
simplification)
$my_reference_to_wp_roles = $wp_roles; // also points to object with
spl_object_hash of "A"
$wp_roles->reinit(); // STILL points to object with spl_object_hash of "A"
}}}
whereas now:
{{{#!php
<?php
global $wp_roles; // points to object with spl_object_hash of "A" (massive
simplification)
$my_reference_to_wp_roles = $wp_roles; // also points to object with
spl_object_hash of "A"
$wp_roles = new WP_Roles(); // NOW points to object with spl_object_hash
of "B" (or C, or anything but A)
}}}
in the latter example, we now have pointers to TWO WP_Roles objects
floating around:
* A local variable pointing to object A (the original $wp_roles global)
* and object B which is a new object that has replaced the global.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/23016#comment:30>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list