[wp-trac] [WordPress Trac] #16867: Where is it appropriate to use filter_var
WordPress Trac
noreply at wordpress.org
Thu Dec 3 18:53:31 UTC 2015
#16867: Where is it appropriate to use filter_var
-------------------------------------------------+-------------------------
Reporter: aaroncampbell | Owner:
Type: enhancement | Status: reopened
Priority: normal | Milestone: Future
Component: General | Release
Severity: normal | Version: 3.2
Keywords: westi-likes needs-patch dev- | Resolution:
feedback | Focuses:
-------------------------------------------------+-------------------------
Comment (by aaroncampbell):
So, here's my new take on this:
First, because you can compile PHP without these, anywhere we use these
we'll really only be moving our exiting functions into compat.php. Which
isn't necessarily bad, but it does mean to me that we need to see enough
benefit from them to make it worth it.
The two most obvious places to use this are still `is_email()` and
`WP_Http::is_ip_address()`.
My tests on using it to replace `is_email()` surprised me. It looks like
filter_var is not only slower, but it doesn't properly handle IP based
E-Mail addresses like ace at 204.32.222.14 (straight from our unit tests).
My tests on IP addresses are a bit more limited, but are also more
promising. It seems that `filter_var( $ip, FILTER_VALIDATE_IP )` is about
2-2.5x faster than `$http->is_ip_address()`. I need a better set of test
data for this though, to make sure it handles all the cases we do. It
doesn't look like we have anything in our unit tests. Does anyone have a
good list of valid and invalid IPs I could drop in to test?
--
Ticket URL: <https://core.trac.wordpress.org/ticket/16867#comment:12>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list