Re: [RFC] Allow Reassignment of Promoted Readonly Properties in Constructor
| From: | Nicolas Grekas | Date: | Tue, 24 Feb 2026 19:34:16 +0000 |
| Subject: | Re: [RFC] Allow Reassignment of Promoted Readonly Properties in Constructor | ||
| References: | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-130158@lists.php.net to get a copy of this message | ||
Le mar. 24 févr. 2026 à 20:06, Larry Garfield <larry@garfieldtech..com> a
écrit :
> On Mon, Feb 23, 2026, at 1:49 AM, Nicolas Grekas wrote:
> > Le dim. 22 févr. 2026 à 19:14, Tim Düsterhus <tim@bastelstu.be> a écrit
> :
> >> Hi
> >>
> >> On 2/19/26 10:49, Nicolas Grekas wrote:
> >> > Thanks, I've added new test cases to cover this.
> >> > I've also improved tests as suggested on the PR.
> >> > And finally I updated the implementation to reuse IS_PROP_REINITABLE
> >> > instead of adding new flags + use an approach that doesn't require
> walking
> >> > the call stack.
> >> > PR and RFC updated accordingly, all green.
> >>
> >> Thank you. The implementation looks much simpler now and the tests all
> >> make sense to me and I can't think of any other relevant “edge case”.
> >>
> >> I have one more comment regarding the RFC text, which should result in
> >> “minor” changes as per the policy of making clarifying changes:
> >>
> >> 1. “Set in child before parent::__construct()” also fails, since the
> >> property slot is not yet initialized:
> >>
> >> That explanation and example does not seem to be quite correct: It's
> not
> >> the
$this->x = 'C'; assignment that
> >> fails, it's the implicit CPP
> >> assignment when calling parent::__construct(). The explanation should
> be
> >> fixed and the // Error: Cannot modify readonly property
> >> P::$x comment
> >> should be moved to the parent::__construct() call.
> >>
> >> The test in the implementation was already correct.
> >>
> >
> > Hi Tim,
> >
> > Good catch thanks, wording updated!
> > The RFC is ready then. Any other comments from anyone else?
> >
> > Nicolas
>
> Two minor non-substantive points.
>
> 1. The "supported operations" section all the way at the bottom seems
> redundant. That was already specified earlier.
>
> 2. It could be helpful to include an example of using property hooks in
> the intro; there's an example of the other 2 options, but not of hooks,
> which are also mentioned as a not-always-ideal alternative. (Let me know
> if you want help or suggestions with that example.)
>
> Otherwise, I'm happy with where this ended up. Thanks!
>
>
Thanks for having a look!
Here is the update:
https://wiki.php.net/rfc/promoted_readonly_constructor_reassign?do=diff&rev2%5B0%5D=1771797005&rev2%5B1%5D=1771961558&difftype=sidebyside
Cheers,
Nicolas