Re: [RFC] Readonly properties

From: Date: Wed, 30 Jun 2021 10:13:43 +0000
Subject: Re: [RFC] Readonly properties
References: 1 2 3 4 5 6 7 8  Groups: php.internals 
Request: Send a blank email to internals+get-115232@lists.php.net to get a copy of this message
> On Jun 29, 2021, at 9:08 AM, Nikita Popov <nikita.ppv@gmail.com> wrote:
> 
> In any case, I don't want to include changes to cloning in this proposal --
> the topic is related, but also orthogonal to readonly properties.
> Unfortunately, it will not be possible to get cloning changes into PHP 8.1
> anymore, due to feature freeze.
> 
> It's okay to vote against this if cloning is a deal breaker. In that case
> I'll probably either work on cloning before re-proposing this,

I while back I made a suggestion for cloning which seemed to resolve the cloning issue in a way that
no other proposals do. 

However, no one acknowledged it, so maybe few if any people saw it?  https://externals.io/message/114729#114747
<https://externals.io/message/114729#114747>

Anyway TL;DR, the approach is to allow specifying a closure on clone, binding $this to it, and then
allow modifications to readonly properties while in that context and anything that it calls:

$clone_obj = clone $obj fn() => {
    $this->foo = 'new value';
}

Would this not be a viable solution for cloning, for this RFC, or the only you work on if this one
fails to pass?

-Mike


Thread (40 messages)

« previous php.internals (#115232) next »