[wp-trac] [WordPress Trac] #48965: Prefer strict PHP comparisons over loose PHP comparisons
WordPress Trac
noreply at wordpress.org
Fri Dec 13 13:29:53 UTC 2019
#48965: Prefer strict PHP comparisons over loose PHP comparisons
-------------------------+-----------------------------
Reporter: pikamander2 | Owner: (none)
Type: enhancement | Status: new
Priority: normal | Milestone: Awaiting Review
Component: General | Version:
Severity: minor | Keywords:
Focuses: |
-------------------------+-----------------------------
My understanding is that it's usually better to use strict comparisons
(===, !==) rather than loose comparisons (==, !=) because they're more
explicit and therefore less prone to silly edge case bugs.
Although it wouldn't affect the logic of the code in some cases, it could
still be helpful for knowing that no implicit type conversion is happening
and therefore making certain things faster to debug. Plus, the process of
converting loose comparisons might reveal some dormant bugs in the code
that would have been difficult to find otherwise.
So, here are some examples of what I'm proposing:
Change this:
if ( $url && $url != network_home_url( '', 'http' ) ) :
to this:
if ( $url && $url !== network_home_url( '', 'http' ) ) :
And this:
if ( $signup->domain . $signup->path == '' ) {
To this:
if ( $signup->domain . $signup->path === '' ) {
And this:
if ( SITECOOKIEPATH != COOKIEPATH ) {
to this:
if ( SITECOOKIEPATH !== COOKIEPATH ) {
I'd be willing to do a lot of the conversions myself, but first I wanted
to see if that's something that we're interested in.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/48965>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list