Skip to content

[DeadCode] Skip array dim fetch assign in RemoveDefaultValueFromAssignedPropertyRector - #8212

Merged
TomasVotruba merged 1 commit into
mainfrom
fix-remove-default-value-array-dim-fetch
Jul 27, 2026
Merged

[DeadCode] Skip array dim fetch assign in RemoveDefaultValueFromAssignedPropertyRector#8212
TomasVotruba merged 1 commit into
mainfrom
fix-remove-default-value-array-dim-fetch

Conversation

@TomasVotruba

@TomasVotruba TomasVotruba commented Jul 27, 2026

Copy link
Copy Markdown
Member

Fixes rectorphp/rector#9826

$this->default['tplset'] = 'dotty'; was treated as a full property assign, because PropertyAssignMatcher intentionally also matches $this->prop[...] = (useful for type inference). A partial array assign does not overwrite the property, so the default value is still required.

Skip the property when it is assigned via array dim fetch, incl. nested dims.

 class ModuleDefine
 {
    private array $default = [
        'name' => 'some name',
        'tplset' => null,
    ];

     public function __construct()
     {
         $this->default['tplset'] = 'dotty';
     }
 }

Before this PR the default value was removed, leaving private array $default; and an uninitialized property → Error: Typed property must not be accessed before initialization.

@TomasVotruba
TomasVotruba merged commit 3ecc536 into main Jul 27, 2026
65 checks passed
@TomasVotruba
TomasVotruba deleted the fix-remove-default-value-array-dim-fetch branch July 27, 2026 14:37
franck-paul added a commit to dotclear/dotclear that referenced this pull request Jul 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Incorrect behavior of RemoveDefaultValueFromAssignedPropertyRector

1 participant