Opened 3 months ago
Closed 3 months ago
#63857 closed defect (bug) (fixed)
Incorrect @var tag for _WP_Dependency::$args
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Milestone: | 6.9 | Priority: | normal |
| Severity: | trivial | Version: | |
| Component: | Script Loader | Keywords: | has-patch |
| Focuses: | docs | Cc: |
Description
_WP_Dependencyinstances are created exclusively viaWP_Dependencies::add(). The constructor of_WP_Dependencysimply assigns up to 5 passed arguments to properties. Except for the third argument, all arguments are asigned as-is.
- In
WP_Dependencies::add(), the fifth parameter$argsis optional, defaults tonull, and is documented asmixed. This value is assigned to_WP_Dependency::$args.
- Currently, core passes at least the value
null(the default ofWP_Dependencies::add()), the value1(see e.g.wp_default_packages_vendor()),arraytypes (e.g., the default ofwp_register_script()), andstringtypes (e.g., the default ofwp_register_style()) as fifth argument.
From 1., _WP_Dependency::__construct() must accept at least the types that WP_Dependencies::add() accepts.
From 2., _WP_Dependency::$args is of type mixed.
From 3., _WP_Dependency::$args must allow array|int|string|null.
Depending on whether types other than array|int|string|null are considered valid for the fifth argument of WP_Dependencies::add(), the @var tag for _WP_Dependency::$args should be updated to array|int|string|null or mixed. If array|int|string|null are the only types considered valid, the documented type of WP_Dependencies::add() should also be updated.
Change History (4)
This ticket was mentioned in PR #9573 on WordPress/wordpress-develop by @iamadisingh.
3 months ago
#2
- Keywords has-patch added
This PR fixes the incorrect @var annotation for the $args property in the _WP_Dependency class. Updated the @var annotation from array to mixed to accurately reflect the actual usage.
Trac ticket: https://core.trac.wordpress.org/ticket/63857
I just noticed that the fifth argument of
wp_register_script()is not passed toWP_Dependencies::add(). Therefore, core does probably not pass anarray.The remainder of the argument still holds.