Make WordPress Core

Opened 9 years ago

Closed 8 years ago

Last modified 8 years ago

#41987 closed enhancement (worksforme)

Should use strict comparison at line 71 in wp-admin/admin.php

Reported by: rnaby Owned by:
Priority: normal Milestone:
Component: Administration Version:
Severity: normal Keywords: close reporter-feedback
Cc: Focuses:

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)

41987.diff (762 bytes ) - added by rnaby 9 years ago.
The diff file I generated after fixing by RabbitVCS.

Download all attachments as: .zip

Change History (6)

@rnaby
9 years ago

The diff file I generated after fixing by RabbitVCS.

#1 @dd32
9 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/

#2 @swissspidy
9 years ago

  • Version trunk

Please note that there's also #41057 to fix coding standards in core once and for all. Much easier than having dozens of very small tickets for things not really worth fixing on their own.

#3 @SergeyBiryukov
9 years ago

  • Component GeneralAdministration

#4 @rnaby
8 years ago

  • Resolutionworksforme
  • Status newclosed

#5 @SergeyBiryukov
8 years ago

  • Milestone Awaiting Review
Note: See TracTickets for help on using tickets.