Make WordPress Core

Opened 11 years ago

Closed 11 years ago

#27133 closed enhancement (fixed)

Redundant type casting in wp_get_object_terms

Reported by: originalexe's profile OriginalEXE Owned by: wonderboymusic's profile wonderboymusic
Milestone: 3.9 Priority: normal
Severity: minor Version: 3.9
Component: Taxonomy Keywords: has-patch
Focuses: Cc:

Description

In wp_get_object_terms function (taxonomy.php), there is a redundant type casting to array after is_array() check has already been performed on that variable.

Attachments (1)

27133.patch (497 bytes) - added by OriginalEXE 11 years ago.
Proposed improvement

Download all attachments as: .zip

Change History (6)

@OriginalEXE
11 years ago

Proposed improvement

#1 @OriginalEXE
11 years ago

  • Keywords has-patch added
  • Severity changed from normal to minor

I have attached a patch removing the unnecessary type casting. It is, however, worth considering replacing all is_array() checks with direct type casting, which appears to be faster in php.

#2 @nacin
11 years ago

Blind type-casting can cause its own hidden issues. (array) null produces array() but (array) false (length of 0) produces array( 0 => false ) (length of 1). It's best to be explicit; is_array() is not exactly slow.

#3 @nacin
11 years ago

  • Milestone changed from Awaiting Review to 3.9

#4 @OriginalEXE
11 years ago

Yeah you're right about that, good point, thanks for clearing it up.

#5 @wonderboymusic
11 years ago

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

In 27186:

Remove extraneous type-casting in wp_get_object_terms().

Props OriginalEXE.
Fixes #27133.

Note: See TracTickets for help on using tickets.