Bug Report
| Subject |
Details |
| Rector version |
last dev-main |
| Installed as |
composer dependency |
Minimal PHP Code Causing Issue
See https://getrector.com/demo/05da0364-f380-433e-b61c-06cd305d5f30
Non-final version:
https://getrector.com/demo/b6044ca3-5d01-4c37-a8ec-7e2f441282b4
<?php
final class DemoFile
{
private string $method;
public static function create(int $a): static
{
$self = new static();
$self->method = 'hi';
$self->method = 'hello';
return $self;
}
}
Responsible rules
Expected Behavior
https://3v4l.org/hv7TE#v8.2.7
This does not work. The rule should not transform the property to readonly, as it is being overwritten immediately.
The rule works properly if new self() instead of new static() is used.
Bug Report
Minimal PHP Code Causing Issue
See https://getrector.com/demo/05da0364-f380-433e-b61c-06cd305d5f30
Non-final version:
https://getrector.com/demo/b6044ca3-5d01-4c37-a8ec-7e2f441282b4
Responsible rules
ReadOnlyPropertyRectorExpected Behavior
https://3v4l.org/hv7TE#v8.2.7
This does not work. The rule should not transform the property to readonly, as it is being overwritten immediately.
The rule works properly if
new self()instead ofnew static()is used.