Re: [VOTE] Allow Reassignment of Promoted Readonly Properties in Constructor
| From: | Rowan Tommins [IMSoP] | Date: | Tue, 24 Mar 2026 18:48:22 +0000 |
| Subject: | Re: [VOTE] Allow Reassignment of Promoted Readonly Properties in Constructor | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-130434@lists.php.net to get a copy of this message | ||
On 24 March 2026 14:06:53 GMT, "Michał Marcin Brzuchalski"
<michal.brzuchalski@gmail.com> wrote:
>So while I understand the motivation behind the RFC, I think this moves
>readonly further toward special-case behavior, when it would be better to
>keep it strict and predictable.
I agree with Ilija and Michal here. I can see why this might seem useful, but the detailed rules
feel very complicated, weakening the value of "readonly".
I think it also weakens the premise of CPP, which was to merge *three* pieces of code: the property
declaration, the parameter declaration, and the assignment.
Perhaps what's actually needed is a variant that only merges the *assignment* with the property
declaration? That would then cover the case mentioned in the RFC with a change in type, as well as
the "readonly" case:
```
class Config {
public function __construct(
?string $cacheDir = null,
) {
public readonly string $this->cacheDir = $cacheDir ?? sys_get_temp_dir() .
'/app_cache';
}
}
```
I'm not sure I love it, but it feels more consistent with the intention of both CPP and
readonly.
Regards,
Rowan Tommins
[IMSoP]