[wp-trac] Re: [WordPress Trac] #8317: New installs: admin has user_level 0

WordPress Trac wp-trac at lists.automattic.com
Tue Nov 25 19:50:34 GMT 2008


#8317: New installs: admin has user_level 0
---------------------+------------------------------------------------------
 Reporter:  Mr Pete  |        Owner:  jacobsantos
     Type:  defect   |       Status:  new        
 Priority:  low      |    Milestone:  2.8        
Component:  Upgrade  |      Version:  2.5        
 Severity:  major    |   Resolution:             
 Keywords:           |  
---------------------+------------------------------------------------------
Comment (by Mr Pete):

 '''Solved it.''' Interesting bug! I learned a bit of new stuff about php.
 And... I believe this same pattern is a problem for some other code.

 The issue: PHP5 automagically passes and returns objects by reference.
 PHP4 passes and returns object copies.
 Documentation of the effect:
 http://www.php.net/manual/en/language.references.return.php

 ''Note:  Unlike parameter passing, here you have to use & in both places -
 to indicate that you return by-reference, not a copy as usual, and to
 indicate that reference binding, rather than usual assignment, should be
 done for $myValue.
 ''

 '''Correct use of get_role() everywhere:'''
 {{{
    $role =& get_role( 'administrator' );
 }}}
 '''Incorrect, and current, use of get_role everywhere:'''
 {{{
    $role = get_role( 'administrator' );
 }}}

 I changed all use of get_role to =& in schema.php and capabilities.php and
 the problem was solved.

 '''This is a VERY easy and simple fix. Any chance it can get bumped?'''

 NOTE: I also searched the code base for other return-by-reference
 functions. There are MANY of these. I checked a few for correct calling
 syntax, and 90% were wrong. (get_categor* calls). Obviously (?) it is not
 a big deal if the caller does not intend to modify the object.

 However, any situation where the object needs to be changed means a PHP4
 incompatibility.

 What a pain!

-- 
Ticket URL: <http://trac.wordpress.org/ticket/8317#comment:20>
WordPress Trac <http://trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list