[wp-trac] [WordPress Trac] #56640: Notice error in WP_List_Util::pluck method at line 169

WordPress Trac noreply at wordpress.org
Fri Sep 23 17:32:23 UTC 2022


#56640: Notice error in WP_List_Util::pluck method at line 169
---------------------------+-----------------------------
 Reporter:  morriswanchuk  |      Owner:  (none)
     Type:  defect (bug)   |     Status:  new
 Priority:  normal         |  Milestone:  Awaiting Review
Component:  General        |    Version:  6.0.1
 Severity:  normal         |   Keywords:
  Focuses:                 |
---------------------------+-----------------------------
 We are seeing intermittent notice errors in our error log:

 {{{
 PHP Notice:  Trying to access array offset on value of type null in
 /application/wp/wp-includes/class-wp-list-util.php on line 169
 }}}

 This is coming from the pluck method in this class on the 'else' portion
 of this code:

 {{{
                                 if ( is_object( $value ) ) {
                                         $newlist[ $key ] = $value->$field;
                                 } else {
                                         $newlist[ $key ] = $value[ $field
 ];
                                 }
 }}}

 I don't know what is causing this error. Our site is large and complex and
 I haven't been able to ascertain a link that will generate this error
 reliably.

 However, it seems to me that this could be rewritten to be "safer".
 Something like this:

 {{{
 if ( is_object( $value ) && property_exists( $value, $field ) ) {
         $newlist[ $key ] = $value->$field;
 } elseif( is_array( $value ) && array_key_exists( $field, $value ) ) {
         $newlist[ $key ] = $value[ $field ];
 }
 }}}

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/56640>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list