[wp-trac] [WordPress Trac] #24674: WP_Query::is_page() should use stricter comparison
WordPress Trac
noreply at wordpress.org
Thu Feb 12 15:54:42 UTC 2015
#24674: WP_Query::is_page() should use stricter comparison
--------------------------+------------------
Reporter: clifgriffin | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: 4.2
Component: Query | Version: 2.5
Severity: minor | Resolution:
Keywords: has-patch | Focuses:
--------------------------+------------------
Comment (by boonebgorges):
I see at least two problems here, both of which come down to the weird
behavior of `is_array()` when the needle is an integer. Both of the
following resolve to `true`:
in_array( 0, array( 'foo' ) );
in_array( 1, array( '1-foo' ) );
We can avoid the weirdness of `is_array()` with integer needle by casting
the needle as a string. See [attachment:24674.2.diff]. I believe this
fixes the bugs in the current ticket, though it'd be nice to get a second
opinion on that.
Switching to strict mode for `is_array()` is another option. However, this
will break backward compatibility in cases like those noted by nacin here
https://core.trac.wordpress.org/ticket/24674#comment:1. We could, more
generously, assume that integer-ish values passed to the function are
intended to be integers. I'm afraid to guess what happens when you have a
page with ID = 123 and another page with page_name = '123'. (Spoiler
alert: I have already guessed.)
--
Ticket URL: <https://core.trac.wordpress.org/ticket/24674#comment:22>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list