Make WordPress Core

Opened 3 months ago

Closed 3 months ago

#63857 closed defect (bug) (fixed)

Incorrect @var tag for _WP_Dependency::$args

Reported by: marian1's profile marian1 Owned by: sergeybiryukov's profile SergeyBiryukov
Milestone: 6.9 Priority: normal
Severity: trivial Version:
Component: Script Loader Keywords: has-patch
Focuses: docs Cc:

Description

  1. _WP_Dependency instances are created exclusively via WP_Dependencies::add(). The constructor of _WP_Dependency simply assigns up to 5 passed arguments to properties. Except for the third argument, all arguments are asigned as-is.
  1. In WP_Dependencies::add(), the fifth parameter $args is optional, defaults to null, and is documented as mixed. This value is assigned to _WP_Dependency::$args.
  1. Currently, core passes at least the value null (the default of WP_Dependencies::add()), the value 1 (see e.g. wp_default_packages_vendor()), array types (e.g., the default of wp_register_script()), and string types (e.g., the default of wp_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)

#1 @marian1
3 months ago

I just noticed that the fifth argument of wp_register_script() is not passed to WP_Dependencies::add(). Therefore, core does probably not pass an array.
The remainder of the argument still holds.

Last edited 3 months ago by marian1 (previous) (diff)

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

#3 @SergeyBiryukov
3 months ago

  • Milestone changed from Awaiting Review to 6.9

#4 @SergeyBiryukov
3 months ago

  • Owner set to SergeyBiryukov
  • Resolution set to fixed
  • Status changed from new to closed

In 60656:

Docs: Correct the type for _WP_Dependency::$args property.

Follow-up to [7970], [25518], [48462].

Props marian1, iamadisingh.
Fixes #63857.

Note: See TracTickets for help on using tickets.