Opened 4 years ago
Closed 4 years ago
#52243 closed enhancement (fixed)
Rename `$this` when used in `@param` tags
Reported by: |
|
Owned by: |
|
---|---|---|---|
Milestone: | 5.7 | Priority: | normal |
Severity: | normal | Version: | |
Component: | Plugins | Keywords: | has-patch |
Focuses: | docs | Cc: |
Description
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 developer.wordpress.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 (6)
Note: See
TracTickets for help on using
tickets.
Hi John, great point!
Maybe we may also want to provide more descriptive params for functions/hooks that are passing
$array
.I found few occurrences, for example:
In
class-requests.php
Or maybe you'll prefer this to be another ticket :)