Problem/Motivation

Drupal\Component\Plugin\Discovery\DiscoveryCachedTrait declares the cached-definitions property as:

/**
 * Cached definitions array.
 *
 * @var array
 */
protected $definitions;

But the runtime semantics allow NULL. Drupal\Core\Plugin\DefaultPluginManager::clearCachedDefinitions() explicitly does $this->definitions = NULL; to invalidate the local in-memory cache, after which getCachedDefinitions() relies on isset($this->definitions) returning FALSE to trigger a re-fetch from the cache backend.

The @var docblock should therefore declare array|null, not array. This is a pure docblock-correctness fix; runtime behavior is unchanged.

Why it matters

Downstream plugin manager classes that extend DefaultPluginManager and override clearCachedDefinitions() (e.g. to walk per-language cache bins for language-aware caching) trip PHPStan's assign.propertyType rule when they do the same $this->definitions = NULL; that core itself does. PHPStan reads the @var docblock as authoritative and flags the assignment as type-violating.

Recent contrib MRs running into this:

  • d.o 3589007 ? core ActionManager language-aware cache.
  • d.o 3589765 ? VBO ViewsBulkOperationsActionManager language-aware cache.

Proposed resolution

Update the @var docblock in DiscoveryCachedTrait from array to array|null.

Issue fork drupal-3590805

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

petar_basic created an issue. See original summary.

petar_basic’s picture

Assigned: petar_basic » Unassigned
Status: Active » Needs review

fago made their first commit to this issue’s fork.

fago’s picture

thanks, small trivial fix, let's move on with this.

I'd call it RTBC if my updated-comment is fine to others.

petar_basic’s picture

Status: Needs review » Reviewed & tested by the community

Makes sense.

petar_basic’s picture

Issue summary: View changes
longwave’s picture

Version: main » 10.6.x-dev
Status: Reviewed & tested by the community » Fixed

Backported down to 10.6.x as a docs fix.

Committed and pushed f93779727eb to main and 7fb559dc13a to 11.x and f11b0563d36 to 11.4.x and 31cf38a13f6 to 10.6.x. Thanks!

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

  • longwave committed 31cf38a1 on 10.6.x
    docs: #3590805 DiscoveryCachedTrait::$definitions @var docblock should...

  • longwave committed f11b0563 on 11.4.x
    docs: #3590805 DiscoveryCachedTrait::$definitions @var docblock should...

  • longwave committed 7fb559dc on 11.x
    docs: #3590805 DiscoveryCachedTrait::$definitions @var docblock should...

  • longwave committed f9377972 on main
    docs: #3590805 DiscoveryCachedTrait::$definitions @var docblock should...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.