[wp-trac] [WordPress Trac] #59774: Undefined array key when using wp_list_pluck function
WordPress Trac
noreply at wordpress.org
Mon Feb 26 17:27:01 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: needs-patch | Focuses:
----------------------------------+-----------------------------
Changes (by hellofromTonya):
* keywords: has-testing-info has-unit-tests has-patch => needs-patch
Comment:
Replying to [comment:16 dd32]:
> This has caused a regression for arrays of objects which have magic
methods for getting properties.
>
> For example:
> {{{
> wp_list_pluck( [ get_user_by('ID', 1) ], 'user_email' );
> }}}
> returns an empty {{{array()}}} while {{{get_user_by('ID',
1)->user_email}}} returns a string.
You're right @dd32. Using your examples:
{{{
var_dump( wp_list_pluck( [ get_user_by('ID', 1) ], 'user_email' ) );
var_dump( get_user_by('ID', 1)->user_email );
}}}
Results before r57698:
{{{
array(1) { [0]=> string(13) "test at test.com" }
string(13) "test at test.com"
}}}
Results after r57698:
{{{
array(0) { }
string(13) "test at test.com"
}}}
There may be other object handle scenarios that need consideration. I
created [https://github.com/WordPress/wordpress-develop/pull/6180 this
patch] to help identify those scenarios and better understand how each
used to work (before r57698) and how they should work.
The goal:
* Identify all of the missing object handling scenarios.
* Add tests for each.
* Figure out a solution for all.
If the above can happen before RC1, then a follow-up commit will be made.
Else, I'd suggest reverting r57698 and moving the ticket to 6.6.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/59774#comment:21>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list