Opened 2 years ago
Last modified 2 years ago
#56640 new defect (bug)
Notice error in WP_List_Util::pluck method at line 169
Reported by: | morriswanchuk | Owned by: | |
---|---|---|---|
Milestone: | Awaiting Review | Priority: | normal |
Severity: | normal | Version: | 6.0.1 |
Component: | General | Keywords: | |
Focuses: | Cc: |
Description
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 ]; }
Change History (2)
Note: See
TracTickets for help on using
tickets.
@morriswanchuk Thanks for reporting this, but this really needs a backtrace to determine where the error is coming from.
I imagine this may not be something which is easy to do with a complex and large site, but it would also help to know if the error still occurs when all plugins are deactivated.
Adding defensive coding is all well an good, but the error is an indication that the class is being used incorrectly, so this should, first and foremost, be solved by identifying the source of the problem and fixing that.