Skip to:

Opened 3 years ago

Closed 20 months ago

Last modified 8 weeks ago

#8611 closed enhancement (fixed)

Rename `$this` when used in `@param` tags

Reported by: espellcaste's profile espellcaste Owned by: espellcaste's profile espellcaste
Milestone: 11.0.0 Priority: low
Severity: trivial Version:
Component: Core Keywords: has-patch


Inspired by and confirmed we have many instances of the same. The description below is basically copied and pasted from that ticket.


Several filters and actions pass $this as a parameter. $this is a pseudo-variable that cannot be used as the name of a function parameter.

I've identified a few problems caused by using $this as the name of a parameter for actions and filters:

  • Inexperienced developers may copy and paste the list of parameters from the apply_filters() call or from the site when adding their filter and then experience a fatal error
  • Developer tools that consume filter and action docblocks, for example code generators, have to rename $this to avoid the same
  • PHPStan and other static analysis tools report $this as invalid when used in a @param tag

Usage of $this in @param tags for actions and filters should be replaced with a more appropriate variable name.

Attachments (1)

8611.patch (56.0 KB) - added by devutpol 2 years ago.
Replace usage of $this in action and filter parameter docblocks.

Download all attachments as: .zip

Change History (11)

#1 @espellcaste
2 years ago

  • Milestone changed from Up Next to 11.0.0

2 years ago

Replace usage of $this in action and filter parameter docblocks.

#2 @devutpol
2 years ago

  • Keywords has-patch added; needs-patch removed

#3 @espellcaste
2 years ago

This looks good! @imath could you also review this patch and confirm the arguments name are okay to you?

#4 @imath
2 years ago

Thanks for the ping @espellcaste and thanks for the patch @devutpol. I quickly had a look about it. But I'll need some more time because I've found something inconsistent at first sight in src/bp-core/classes/class-bp-email-recipient.php $recipient being used for BP_Email_Recipient and BP_Email, BP_Email is more representing a full email object with subject, content, sender and recipient.

#5 @espellcaste
21 months ago

@imath Any feedback?

This ticket was mentioned in Slack in #buddypress by imath. View the logs.

21 months ago

This ticket was mentioned in Slack in #buddypress by espellcaste. View the logs.

20 months ago

#8 @imath
20 months ago

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

In 13372:

Replace usage of $this in @param tags with a meaningful variable name

Props devutpol, espellcaste

Fixes #8611

#9 @imath
18 months ago

In 13421:

Add missing backticks in @since docblock

This commit is mainly an attempt to make sure a contributor rightly gets a
BuddyPress badge on his WordPress profile page.

Props devutpol

See #8611

Note: See TracTickets for help on using tickets.