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
ActionManagerlanguage-aware cache. - d.o 3589765 ? VBO
ViewsBulkOperationsActionManagerlanguage-aware cache.
Proposed resolution
Update the @var docblock in DiscoveryCachedTrait from array to array|null.
Issue fork drupal-3590805
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
Comment #3
petar_basic commentedComment #5
fagothanks, small trivial fix, let's move on with this.
I'd call it RTBC if my updated-comment is fine to others.
Comment #6
petar_basic commentedMakes sense.
Comment #7
petar_basic commentedComment #8
longwaveBackported 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!