Skip to content

[Php81] Skip ReadOnlyPropertyRector on property changed via reference in foreach#8118

Merged
TomasVotruba merged 1 commit into
mainfrom
tv-skip-ro
Jun 30, 2026
Merged

[Php81] Skip ReadOnlyPropertyRector on property changed via reference in foreach#8118
TomasVotruba merged 1 commit into
mainfrom
tv-skip-ro

Conversation

@TomasVotruba

Copy link
Copy Markdown
Member

Skip making a property readonly when its array is mutated through a by-reference foreach (foreach ($this->items as &$item)).

Such a property is still being written to after its initial assignment, so marking it readonly would cause a "Cannot modify readonly property" runtime error.

final class SomeClass
{
    private array $relativeDateStrings;

    public function __construct()
    {
        $this->relativeDateStrings = ['yesterday', 'today'];
        foreach ($this->relativeDateStrings as &$string) {
            $string = strtoupper($string);
        }
    }
}

@TomasVotruba TomasVotruba merged commit 1d57d98 into main Jun 30, 2026
65 checks passed
@TomasVotruba TomasVotruba deleted the tv-skip-ro branch June 30, 2026 09:05
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.

1 participant