#41987 closed enhancement (worksforme)
Should use strict comparison at line 71 in wp-admin/admin.php
Reported by: | rnaby | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | |
Component: | Administration | Keywords: | close reporter-feedback |
Focuses: | Cc: |
Description
Well, the both side of comparison has already been same data type, but I think it would be better if the comparison would be strict !
Before or now the code looks like this-
if ( $c <= 50 || ( $c > 50 && mt_rand( 0, (int)( $c / 50 ) ) == 1 ) ) {
After fix the code looks like this-
if ( $c <= 50 || ( $c > 50 && mt_rand( 0, (int)( $c / 50 ) ) === 1 ) ) {
I think the later approach is better.
Attachments (1)
Change History (6)
#1
@
7 years ago
- Keywords close reporter-feedback added
I don't I see any benefit in strict type checking in scenario's like this or #41988
As mt_rand()
only returns int
or false
and we don't really need to care about any non-int return values, especially in this section of code.
A scenario where it would be useful is cases where "falsey" values are expected, such as #21249
What benefit does the proposed changes actually give?
FWIW our PHP Coding Standards are available here: https://make.wordpress.org/core/handbook/best-practices/coding-standards/php/
The diff file I generated after fixing by RabbitVCS.