Re: [RFC] [DISCUSSION] Immutable/final/readonly properties
| From: | Larry Garfield | Date: | Mon, 16 Mar 2020 15:41:09 +0000 |
| Subject: | Re: [RFC] [DISCUSSION] Immutable/final/readonly properties | ||
| References: | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-109064@lists.php.net to get a copy of this message | ||
On Mon, Mar 16, 2020, at 6:57 AM, Nicolas Grekas wrote:
> Le lun. 16 mars 2020 à 12:52, Máté Kocsis <kocsismate90@gmail.com> a écrit :
>
> > >
> > > The other one is the recently declined
> > > https://wiki.php.net/rfc/object-initializer. As it
> > > basically works by
> > > first
> > > creating the object normally (including a possible constructor call), and
> > > then assigning the specified properties, this would not be compatible
> > with
> > > readonly properties that have defaults. Other implementation approaches
> > are
> > > possible though, but may not be easily reconcilable with the need to also
> > > call the constructor.
> > >
> >
> > I think what I'd expect from a possible object initializer feature is that
> > it
> > can't overwrite "write-once" properties with default values. (?)
> >
> > However, I'm ok to to remove support for default values because of the
> > possible
> > problems outlined (confusion for end users, uncertainty how it'd work
> > together with new
> > features etc.). It seems that the replies are more on this side, so let's
> > be a bit more
> > conservative than I originally wanted to be, so that we have more freedom
> > later.
> >
> > Actually, I have already updated the RFC with this. Also, I made some
> > clarifications
> > in connection with serialization and the usage of resources.
> >
>
>
> I repeat what I wrote before but all those problems would disappear if we
> were to bind the proposal to visibility:
> https://externals.io/message/108675#108753
>
> We could even consider splitting "read" and "write" in two separate
> keywords, each bound to visibility, isn't it?
How would 2 separate keywords work, syntactically/visually? I can see how it would solve a larger
cluster of use cases, but I'm not sure what the code would look like. :-)
--Larry Garfield