Make WordPress Core

Opened 2 years ago

Last modified 10 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) {
  [0]=>
  string(4) "val1"
  [1]=>
  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) {
  ["key1"]=>
  string(4) "val1"
  ["key2"]=>
  string(4) "val2"
}

Attachments (2)

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

Download all attachments as: .zip

Change History (9)

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


2 years ago
#1

  • 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.](https://core.trac.wordpress.org/ticket/57136)
](https://core.trac.wordpress.org/ticket/57136)](https://core.trac.wordpress.org/ticket/57136)

#2 @afragen
2 years ago

Related #56650

#3 @riccardodicurti
2 years 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
2 years 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
2 years 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.

https://core.trac.wordpress.org/raw-attachment/ticket/57136/Screenshot%202022-11-19%20at%2014.16.56.png

Ticket #57136

Using this patch the output is correct.

https://core.trac.wordpress.org/raw-attachment/ticket/57136/Screenshot%202022-11-19%20at%2014.19.07.png

Last edited 2 years ago by riccardodicurti (previous) (diff)

#6 @hellofromTonya
21 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
10 months ago

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