WordPress.org

Make WordPress Core

Opened 2 years ago

Closed 2 years ago

Last modified 14 months ago

#41981 closed enhancement (fixed)

link-template.php: if ($x = $y ) vs if ($x == $y)

Reported by: danimalbrown Owned by: SergeyBiryukov
Milestone: 5.1 Priority: low
Severity: normal Version:
Component: Permalinks Keywords: 2nd-opinion has-patch
Focuses: Cc:
PR Number:

Description

While reading through the code I came across line 189 of wp-includes/link-template.php (WordPress 4.8.2):

if ( $parent = $category_object->parent )

I don't have a behavior to reflect this but it looks like the common bug where the incorrect single equals sign appears in a conditional. There should probably be 2 or 3 equal signs here.

Attachments (1)

41981.patch (744 bytes) - added by JPry 2 years ago.

Download all attachments as: .zip

Change History (7)

#1 @JPry
2 years ago

  • Keywords 2nd-opinion has-patch added

Hi @danimalbrown, welcome to Trac! In this particular instance, the $parent variable is being set deliberately. It is subsequently used within the next line:

<?php
if ( $parent = $category_object->parent )
        $category = get_category_parents($parent, false, '/', true) . $category;

The $parent variable isn't used anywhere else within that function. This certainly is a confusing section of code, and it was a good idea to call it out as a potential issue.

Generally, something like this wouldn't be changed for the sole purpose of bringing it into line with the WordPress Coding Standards, but there may be room to eliminate the $parent variable in order to help clear up the confusion.

I'll upload a patch.

@JPry
2 years ago

#2 @danimalbrown
2 years ago

Thanks @JPry for the clarification and for providing a patch. The patch definitely makes it more clear for someone looking over the code for the first time.

#3 @swissspidy
2 years ago

  • Component changed from General to Permalinks
  • Priority changed from normal to low
  • Type changed from defect (bug) to enhancement
  • Version 4.8.2 deleted

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.

#4 @SergeyBiryukov
2 years ago

  • Milestone changed from Awaiting Review to 5.0

#5 @SergeyBiryukov
2 years ago

  • Owner set to SergeyBiryukov
  • Resolution set to fixed
  • Status changed from new to closed

In 42378:

Permalinks: Remove unnecesary temporary variable in get_permalink().

Props JPry, danimalbrown.
Fixes #41981.

#6 @johnbillion
14 months ago

  • Milestone changed from 5.0 to 5.1
Note: See TracTickets for help on using tickets.