#16137 closed defect (bug) (fixed)
wp_list_filter() is inexact when dealing with nested arrays
Reported by: | scribu | Owned by: | ryan |
---|---|---|---|
Milestone: | 3.3 | Priority: | normal |
Severity: | normal | Version: | |
Component: | General | Keywords: | has-patch |
Focuses: | Cc: |
Description (last modified by )
To reproduce:
add_action('init', 'test_admin_notices', 11); function test_admin_notices() { global $wp_taxonomies; print_r( wp_filter_object_list( array_values( $wp_taxonomies ), array( 'object_type' => array( 'post' ) ), 'and', 'object_type' ) ); }
This is because array_intersect_assoc() does a strict comparison: (string) $elem1 === (string) $elem2
Using a manual loop fixes the problem.
Attachments (6)
Change History (23)
#3
@
13 years ago
- Cc mark@… added
I just came across this problem. The bug breaks get_taxonomies( $args, $output, $operator )
when $args = array('object_type' => array($custom_post_type))
, but the patch fixes it. Can we get this in 3.2?
#4
@
13 years ago
- Keywords needs-refresh 3.2-early removed
- Milestone changed from Future Release to 3.3
#5
follow-up:
↓ 7
@
13 years ago
While we're at it, we should use get_object_vars() instead of casting to array, in case the object has non-public properties, which we don't care about.
#7
in reply to:
↑ 5
@
13 years ago
Replying to scribu:
While we're at it, we should use get_object_vars() instead of casting to array
Done.
#12
@
13 years ago
add unit tests, i'm not exactly certain of the correct behaviour and cases for test_filter_object_list_nested_array_or
and also test_filter_object_list_or_nested_array_or_field
, any guidance would be appreciated. any other cases required?
#13
@
13 years ago
It seems using a foreach is actually faster than array_intersect_assoc().
Using wplf-test.php I get:
wp_list_filter_old: 1.6865890026093 wp_list_filter_new: 1.3801169395447 wp_list_filter_new2: 1.871533870697
wp_list_filter_new is the one in 16137.patch.
wp_list_filter_new2 uses an if + get_object_vars(). Although I made this suggestion, I think it's better to just use casting to arrays.
Context: #14084