[wp-trac] [WordPress Trac] #50095: WP_List_Util::filter() not compatible with lists of objects that use magic methods
WordPress Trac
noreply at wordpress.org
Wed May 6 01:54:48 UTC 2020
#50095: WP_List_Util::filter() not compatible with lists of objects that use magic
methods
-----------------------------+------------------------------
Reporter: johnjamesjacoby | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Formatting | Version: 4.7
Severity: normal | Resolution:
Keywords: | Focuses:
-----------------------------+------------------------------
Comment (by johnjamesjacoby):
[https://core.trac.wordpress.org/attachment/ticket/50095/50095.patch
50095.patch] suggests changing `WP_List_Util::filter()` to only use
`array_key_exists()` when the item is actually an `array`. When the item
is of type `object` then it will use `isset()` instead, allowing it to be
compatible with magic `__isset()` and friends.
Here is a [https://www.php.net/manual/en/function.array-key-
exists.php#115453 comment from php.net] identifying a similar issue with
`array_key_exists()`.
With this patch attached, tests appear to pass, and the above code example
correctly outputs:
{{{
array (size=1)
1 =>
object(Thing)[616]
public 'data' =>
array (size=1)
'greeting' => string 'howdy' (length=5)
}}}
--
Ticket URL: <https://core.trac.wordpress.org/ticket/50095#comment:1>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list