[wp-trac] [WordPress Trac] #59774: Undefined array key when using wp_list_pluck function
WordPress Trac
noreply at wordpress.org
Thu Feb 22 21:48:47 UTC 2024
#59774: Undefined array key when using wp_list_pluck function
-------------------------------------------------+-------------------------
Reporter: iamarunchaitanyajami | Owner:
| hellofromTonya
Type: defect (bug) | Status: reviewing
Priority: normal | Milestone: 6.5
Component: General | Version: 5.1
Severity: normal | Resolution:
Keywords: has-patch has-testing-info has- | Focuses:
unit-tests commit |
-------------------------------------------------+-------------------------
Comment (by hellofromTonya):
Hmm wait. Upon a deeper look, this ticket is resolving 2 the PHP warning
and setting `null` for the item in the returned list.
When comparing the results of:
{{{#!php
$input_list = array(
array( '123' => '456' ),
array( 'foo' => 'bar' ),
array( 'foo' => 'baz' ),
);
var_dump( array_column( $input_list, 'foo', null ) );
var_dump( wp_list_pluck( $input_list, 'foo', null ) );
}}}
`array_column()` prints:
{{{
array(2) {
[0]=>
string(3) "bar"
[1]=>
string(3) "baz"
}
}}}
but `wp_list_pluck()` prints:
{{{
Warning: Undefined array key "foo" in ...
array(3) {
[0]=>
NULL
[1]=>
string(3) "bar"
[2]=>
string(3) "baz"
}
}}}
Notice the difference. The first element is `null`. So the issue is more
than the a PHP Warning, as the `NULL` should not be there.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/59774#comment:12>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list