[wp-trac] [WordPress Trac] #48142: Let's do some `phpcbf` cleanup...
WordPress Trac
noreply at wordpress.org
Sun Sep 29 23:19:35 UTC 2019
#48142: Let's do some `phpcbf` cleanup...
-------------------------------------+------------------------
Reporter: whyisjake | Owner: whyisjake
Type: defect (bug) | Status: closed
Priority: normal | Milestone: 5.3
Component: General | Version: trunk
Severity: normal | Resolution: fixed
Keywords: has-patch needs-refresh | Focuses:
-------------------------------------+------------------------
Changes (by SergeyBiryukov):
* status: reopened => closed
* resolution: => fixed
Comment:
Replying to [comment:10 jrf]:
> Re: [46316] - this may lead to difficult to debug issues unless you are
100% sure both sides of the comparison will always be numeric.
Effectively, the change makes no difference to the code and it is still a
loose type comparison, as the `(int)` cast is what PHP would do internally
when using `!=`.
>
> So if a true strict type comparison is intended here, a string-based
strict comparison should be used:
> {{{#!php
> <?php
> if ( $cat_id !== (string) $category ) {
> }}}
Thanks for the feedback! After some consideration, I'd like to leave that
part as is, for a few reasons:
* [46316] was not meant to introduce the strict comparison, only to fix
the issue introduced in [46313]. I've decided to double-check the change
in [46313] and confirmed my suspicions, as the types were indeed
different, hence the fix in [46316]. In my testing, this worked as
expected, and did make a difference to the code.
* Link Manager was deprecated in core 7 years ago (#21307), so there
should not be any changes to data structures there in the forseeable
future, and it's safe to assume both sides of the comparison will always
be numeric.
* I don't mind converting this check to `(string)`, however `(int)` seems
more consistent with other similar checks in core:
* 29 matches for `\(int\) [$a-z_]+? (=|!)==` or `(=|!)== \(int\)`
* 2 matches for `\(string\) [$a-z_]+? (=|!)==` or `(=|!)== \(string\)`
--
Ticket URL: <https://core.trac.wordpress.org/ticket/48142#comment:14>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list