[wp-trac] [WordPress Trac] #34172: wp_list_pluck missing checks

WordPress Trac noreply at wordpress.org
Wed Oct 7 02:47:53 UTC 2015


#34172: wp_list_pluck missing checks
--------------------------+--------------------------
 Reporter:  wpsmith       |       Owner:
     Type:  defect (bug)  |      Status:  closed
 Priority:  normal        |   Milestone:
Component:  General       |     Version:  trunk
 Severity:  normal        |  Resolution:  wontfix
 Keywords:                |     Focuses:  performance
--------------------------+--------------------------
Changes (by boonebgorges):

 * status:  new => closed
 * resolution:   => wontfix
 * milestone:  Awaiting Review =>


Comment:

 The problems described in #34175 arise from the (incorrect?) use of the
 `get_terms_fields` filter and the `fields` param in `get_terms()`. Things
 like `update_term_cache()` should only be called with full term objects. I
 don't think that any modifications to `wp_list_pluck()` can help with
 that.

 Thinking more about the suggestions in this ticket, I think we should not
 move forward with it. We definitely should not be skipping indexes in the
 case where they're not set. This will result in the arrays being returned
 from `wp_list_pluck()` sometimes having fewer items than the array passed
 to it. It also means that numerically indexed arrays will have non-
 consecutive indexes after plucking. Both of these seem bad, and likely to
 cause errors.

 The alternative strategy would be to fill `null` for indexes that don't
 have the requested field. So:

 {{{
 $before = array(
     'a' => array( 'foo' => 'bar' ),
     'b' => array(),
     'c' => array( 'foo' => 'baz' ),
 );

 $after = wp_list_pluck( $before, 'foo' );
 // array(
 //     'a' => 'bar',
 //     'b' => null,
 //     'c' => 'baz',
 // )

 But even this is going to create ambiguity when you have an array where
 fields can legitimately contain the `null` value.

 The potential for confusion is not worth the potential benefits,
 especially when the benefits are slight - as noted above, PHP notices like
 the ones you've described can be helpful tips that a developer is doing
 something wrong.
 }}}

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


More information about the wp-trac mailing list