Make WordPress Core

Opened 19 months ago

Last modified 4 months ago

#57136 new defect (bug)

wp_list_pluck's key argument not working correctly when its zero

Reported by: dgwatkins's profile dgwatkins Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 4.7
Component: General Keywords: has-patch needs-testing
Focuses: Cc:

Description (last modified by costdev)

This is better explained with an example:

wp> var_dump( wp_list_pluck( [ [ 'key1', 'val1' ], [ 'key2', 'val2' ] ], 1, 0 ));
array(2) {
  string(4) "val1"
  string(4) "val2"

See the missing key?

If we try with array_column it works correctly:

wp> var_dump( array_column( [ [ 'key1', 'val1' ], [ 'key2', 'val2' ] ], 1, 0 ));
array(2) {
  string(4) "val1"
  string(4) "val2"

Attachments (2)

Screenshot 2022-11-19 at 14.16.56.png (106.0 KB) - added by riccardodicurti 19 months ago.
Screenshot 2022-11-19 at 14.19.07.png (108.0 KB) - added by riccardodicurti 19 months ago.

Download all attachments as: .zip

Change History (9)

This ticket was mentioned in PR #3643 on WordPress/wordpress-develop by @riccardodicurti.

19 months ago

  • Keywords has-patch added


Trac ticket:

This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.](

#3 @riccardodicurti
19 months ago

Hi @afragen, may I ask what you mean with "related #56650". Should this ticket be closed? I don't see the same change in the other ticket.

#4 @afragen
19 months ago

I said _related_ as the other ticket also deals with arguments to wp_list_pluck(). The other ticket goes about solving this issue a bit differently and also includes tests.

If you could test the PR for the ticket and see if it also fixes your issue that would be great. If it does, I would recommend closing this ticket as a duplicate.

#5 @riccardodicurti
19 months ago

  • Keywords needs-testing added
  • Version set to trunk

Hi @afragen, I tested your PR and unfortunately it doesn't solve the problem reported in this ticket.

Ticket #56650

As you can see, the output is like the one reported in this ticket.

Ticket #57136

Using this patch the output is correct.

Version 0, edited 19 months ago by riccardodicurti (next)

#6 @hellofromTonya
16 months ago

  • Version changed from trunk to 4.7

I'm doing some 6.2 triage work ahead of RC1 for tickets reported as Version trunk (i.e. trunk is currently 6.2.0). This issue was not introduced in 6.2.0.

The code was introduced in 4.7.0 via [38928] / #37128. Changing the Version number to 4.7.

Noting, this ticket is a follow-up to [55423] / #56650.

#7 @costdev
4 months ago

  • Description modified (diff)
Note: See TracTickets for help on using tickets.