Make WordPress Core

Opened 2 weeks ago

Last modified 2 weeks ago

#54751 new defect (bug)

Invalid argument in class-wp-list-util.php

Reported by: marv2 Owned by:
Milestone: 6.0 Priority: normal
Severity: normal Version: 3.1
Component: General Keywords: good-first-bug needs-patch needs-unit-tests
Focuses: Cc:


I've been getting this error since v5.8.2.

Seems to be coming from WP core.

PHP Warning:  Invalid argument supplied for foreach() in /htdocs/wp-includes/class-wp-list-util.php on line 164

Change History (1)

#1 @davidbaumwald
2 weeks ago

  • Keywords good-first-bug needs-patch needs-unit-tests added
  • Milestone changed from Awaiting Review to 6.0
  • Version changed from 5.8.2 to 3.1

@marv2 Welcome to WordPress Core Trac, and thanks for the ticket!

This can happen when using the wp_list_pluck function which, in the underlying WP_List_Util class expects the list to be an array.

I think adding some checks before iterating over the array in WP_List_Util->pluck to ensure the list is an actual array would be nice to get rid of this warning. Perhaps throwing a _doing_it_wrong is also needed?

Also, going to tag this for needs-unit-tests. It would be good to have some "unhpappy path" tests to check some invalid types sent to the pluck method.

Last edited 2 weeks ago by davidbaumwald (previous) (diff)
Note: See TracTickets for help on using tickets.