[wp-trac] [WordPress Trac] #59774: Undefined array key when using wp_list_pluck function

WordPress Trac noreply at wordpress.org
Mon Feb 26 00:00:02 UTC 2024


#59774: Undefined array key when using wp_list_pluck function
-------------------------------------------------+-------------------------
 Reporter:  iamarunchaitanyajami                 |       Owner:
                                                 |  hellofromTonya
     Type:  defect (bug)                         |      Status:  reopened
 Priority:  normal                               |   Milestone:  6.5
Component:  General                              |     Version:  5.1
 Severity:  normal                               |  Resolution:
 Keywords:  has-patch has-testing-info has-      |     Focuses:
  unit-tests commit                              |
-------------------------------------------------+-------------------------

Comment (by dd32):

 My initial thought is that something like this could be used:
 {{{
 if ( property_exists( $object, $field ) || isset( $object->$field ) )
 }}}

 That should work in the following scenario's:
  - Property exists (may be null)
  - Property is magic, `__get()` may return null, `__isset()` properly
 handles null values (ie. does isset(), or checks a property exists in the
 child object, or has a static list of magic keys)

 It would not work when:
  - Property is magic, `__get()` returns null, `__isset()` fails to handle
 `null` values, ie. only does an isset() check that doesn't return truthful
 for null fields.

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


More information about the wp-trac mailing list