#8611 closed enhancement (fixed)
Rename `$this` when used in `@param` tags
Reported by: |
|
Owned by: |
|
---|---|---|---|
Milestone: | 11.0.0 | Priority: | low |
Severity: | trivial | Version: | |
Component: | Core | Keywords: | has-patch |
Cc: |
Description
Inspired by https://core.trac.wordpress.org/ticket/52243 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 https://developer.buddypress.org 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)
Change History (11)
#3
@
2 years ago
This looks good! @imath could you also review this patch and confirm the arguments name are okay to you?
#4
@
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.
Replace usage of $this in action and filter parameter docblocks.