Opened 5 years ago
Closed 5 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
$thisto avoid the same - PHPStan and other static analysis tools report
$thisas invalid when used in a@paramtag
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/** * Convert a key => value array to a 'key: value' array for headers * * @param array $array Dictionary of header values * @return string[] List of headers */ public static function flatten($array) {Or maybe you'll prefer this to be another ticket :)