Opened 3 years ago

Closed 3 years ago

#12375 closed enhancement (fixed)

HTTP class contains redundant defined() check

Reported by: TobiasBg Owned by: nacin
Priority: normal Milestone: 3.0
Component: HTTP Version:
Severity: normal Keywords: has-patch commit
Cc:

Description

Line 554 of wp-includes/class-http.php contains a somewhat redundant logic:

if ( ! defined('WP_HTTP_BLOCK_EXTERNAL') || ( defined('WP_HTTP_BLOCK_EXTERNAL') && WP_HTTP_BLOCK_EXTERNAL == false ) )
The part after the
will only be executed if the constant is defined, thus it's overhead to check that again. Also checking constants for false (like WP_HTTP_BLOCK_EXTERNAL == false) is not good practice.

I have attached two patches, one that simply removes the redundant check and simplifies the WP_HTTP_BLOCK_EXTERNAL == false to ! WP_HTTP_BLOCK_EXTERNAL.
The second patch has the same logic, but has De Morgan's laws applied. I could decide what looks better :-)

Attachments (2)

12375-a.patch (605 bytes) - added by TobiasBg 3 years ago.
Patch to fix reduncancy and clean up comparison
12375-b.patch (607 bytes) - added by TobiasBg 3 years ago.
Same patch, but with De Morgan's laws applied

Download all attachments as: .zip

Change History (8)

Patch to fix reduncancy and clean up comparison

Same patch, but with De Morgan's laws applied

I'm pretty sure we do this redundancy in multiple places. Used to be more, though I know we've eliminated some of them.

I grep'ed through the core source, but couldn't find any more occurances.

There are three or four more files that have two defined() checks in one line, but those check for different constants.

Fair enough, looks like this is the last one then.

  • Owner changed from dd32 to nacin
  • Status changed from new to accepted
  • Resolution set to fixed
  • Status changed from accepted to closed

(In [13422]) Clean up redundant defined() check. Props TobiasBg fixes #12375

Note: See TracTickets for help on using tickets.