[wp-trac] [WordPress Trac] #8150: walker class special case

WordPress Trac wp-trac at lists.automattic.com
Tue Nov 11 01:33:06 GMT 2008


#8150: walker class special case
---------------------+------------------------------------------------------
 Reporter:  hailin   |       Owner:  anonymous
     Type:  defect   |      Status:  new      
 Priority:  normal   |   Milestone:  2.8      
Component:  General  |     Version:           
 Severity:  normal   |    Keywords:           
---------------------+------------------------------------------------------
 In function walk( $elements, $max_depth),
 when none of the elements is top level (parent = 0)
 we assume the first one must be root of the sub elements.
 and get it as $root = $elements[0].

 This implicitly assumes that the first index is 0.
 In fact, in some cases, it can start with any integer.
 It's observed that it can start with 2. When that happens,
 walker will not construct any top level elements, end up treating
 all as orphans.

 The better and safe, way is to user array function:

 $first = array_slice( $elements, 0, 1 );
 $root = $first[0];

-- 
Ticket URL: <http://trac.wordpress.org/ticket/8150>
WordPress Trac <http://trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list