[wp-trac] [WordPress Trac] #16895: wp_list_pluck cannot be used with arrays of references

WordPress Trac wp-trac at lists.automattic.com
Sat Mar 19 11:47:38 UTC 2011


#16895: wp_list_pluck cannot be used with arrays of references
--------------------------+----------------------------
 Reporter:  dd32          |      Owner:
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Future Release
Component:  General       |    Version:  3.1
 Severity:  normal        |   Keywords:  has-patch
--------------------------+----------------------------
 Example code:

 {{{
 $one = array('num' => 1);
 $two = array('num' => 2);
 $input = array( &$one, &$two );

 $nums = wp_list_pluck($input, 'num');

 var_dump($nums, $input);
 }}}

 Example output:
 {{{
 array
   0 => &int 1
   1 => &int 2
 array
   0 => &int 1
   1 => &int 2
 }}}
 Expected output:
 {{{
 array
   0 => int 1
   1 => int 2
 array
   0 => &
     array
       'num' => int 1
   1 => &
     array
       'num' => int 2
 }}}

 This is caused by wp_list_pluck using the same variable name for the input
 array, and then overwriting it for the return.

 One such real life example, is $wp_query->comments

 See patch

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


More information about the wp-trac mailing list