Make WordPress Core

Opened 6 years ago

Closed 6 years ago

#44927 closed enhancement (fixed)

Unnecessary is_null() call in get_avatar_data()

Reported by: jpry's profile JPry Owned by: sergeybiryukov's profile SergeyBiryukov
Milestone: 5.1 Priority: normal
Severity: minor Version:
Component: Users Keywords: has-patch
Focuses: Cc:

Description

In the get_avatar_data() function, this check comes immediately after the pre_get_avatar_data filter:

<?php
        if ( isset( $args['url'] ) && ! is_null( $args['url'] ) ) {
                /** This filter is documented in wp-includes/link-template.php */
                return apply_filters( 'get_avatar_data', $args, $id_or_email );
        }

The ! is_null() portion of the condition is unnecessary, because isset() checks whether a variable is set and is not null (http://php.net/manual/en/function.isset.php).

Attachments (2)

44927.patch (584 bytes) - added by JPry 6 years ago.
isset-vs-isnull.png (24.9 KB) - added by mukesh27 6 years ago.

Download all attachments as: .zip

Change History (14)

@JPry
6 years ago

#1 @mukesh27
6 years ago

  • Component changed from General to Users
  • Type changed from defect (bug) to enhancement

#2 follow-up: @mukesh27
6 years ago

@JPry check attached image for difference between isset and is_null.

#3 in reply to: ↑ 2 @JPry
6 years ago

Replying to mukesh27:

@JPry check attached image for difference between isset and is_null.

@mukesh27 I'm not sure what you're trying to show. I'm aware of the difference in isset() and is_null(), which is why I opened this ticket.

#4 follow-up: @mukesh27
6 years ago

if $args['url'] value is empty then isset is not working.

#5 in reply to: ↑ 4 @JPry
6 years ago

Replying to mukesh27:

if $args['url'] value is empty then isset is not working.

This is about the use of isset( $args['url'] ) $$ ! is_null( $args['url'] ). It doesn't check using empty(), and I don't think it should be using empty(). This is because of the filter that comes directly above this statement. Please refer to the source code inline to see for yourself.

#6 @SergeyBiryukov
6 years ago

  • Milestone changed from Awaiting Review to 4.9.9
  • Owner set to SergeyBiryukov
  • Status changed from new to reviewing

#7 @pento
6 years ago

  • Milestone changed from 4.9.9 to 5.0.1
  • Version trunk deleted

#8 @pento
6 years ago

  • Milestone changed from 5.0.1 to 5.0.2

#9 @pento
6 years ago

  • Milestone changed from 5.0.2 to 5.0.3

#10 @SergeyBiryukov
6 years ago

  • Milestone changed from 5.0.3 to 5.1

#11 @SergeyBiryukov
6 years ago

Introduced in [31107].

#12 @SergeyBiryukov
6 years ago

  • Resolution set to fixed
  • Status changed from reviewing to closed

In 44351:

Users: Remove unnecessary is_null() call in get_avatar_data().

The ! is_null() portion of the condition is unnecessary, because isset() checks whether a variable is set *and* is not null.

Props JPry.
Fixes #44927.

Note: See TracTickets for help on using tickets.