Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
PHPStan has identified possible undefined variables in cases where we include files, in the color module and the transliteration component. This is because the variables are set inside the included files, but PHPStan cannot be sure this is happening.
Steps to reproduce
Proposed resolution
Set default values for the variables before including the file.
Remaining tasks
User interface changes
API changes
Data model changes
Release notes snippet
Comment | File | Size | Author |
---|---|---|---|
#2 | 3259110-2.patch | 2.75 KB | longwave |
|
Comments
Comment #2
longwaveComment #3
mglamanReviewed the code and ran PHPStan locally. Fixes the errors and ensures that the variables initiated before including the files.
Not entirely relevant to the issue at hand, but it'd be better if we ran the include in a static closure with the minimum variables passed.
Here's an example from PHPStan itself:
In these cases we could leverage
use
to pass items by reference.Comment #4
daffie CreditAttribution: daffie commented+1 for RTBC.
Comment #5
alexpottCommitted f29ceb6 and pushed to 10.0.x. Thanks!
There is a subtle behaviour change here. If the file sets $overrides to something other then an array this would result in it being set. However setting it to something other than an array is an error so it's probably better to fail here.
#3 seems worth a follow-up as it'd further insulate from side-effects.