On Mon, Sep 5, 2022 at 9:57 AM Nicolas Grekas
<nicolas.grekas+...@gmail.com> wrote:
>
> >Hi Marco,
> > >
> > >IMO good as-is: can be relaxed later (8.3 or later), if anybody believes
> > >> it's a show-stopper.
> > >>
> > >Readonly classes don't really need to be lazy.
> > >>
> > >
> > >"Break things and move slow" doesn't feel right to me for the language.
> >
> > It's a new keyword that you have to opt into. So it's not breaking
> > anything. It just means you might not be able to use it for your use case
> > yet.
> >
> > (and before you say that third party code might add it, you can just say
> > you don't support it yet).
> >
>
> It's not like it wouldn't be supported *yet*. It won't be supported *by
> design of the language*.
>
> Readonly classes introduce a new concept that isn't backed by any language
> theory I've read about.
> Of course it doesn't break until you use it, but conceptually, it breaks a
> universal design pattern: inheritance-based proxy decorators.
> What I'm asking for is: what is the justification for this limitation? If
> there is none, we should drop it. Preemptively breaking universal concepts
> (decoration) by introducing a never-seen concept might be innovation for
> sure. Or it might be a mistake. E.g. do we know any other language that
> provides something like readonly classes? How do they deal with inheritance?
> Can anyone answer those questions?
>
> If we come to the conclusion that there is no backing theory to support
> propagating the readonly flag to child classes, then we might decide if we
> want to fix this in 8.2 or 8.3. I know I would prefer acting in 8.2, but
> that's a separate discussion.
>
> Nicolas

> do we know any other language that provides something like readonly classes? 
> How do they deal with inheritance?

C# has readonly structs, but inheritance isn't allowed with structs so
they slightly side-step this problem.
(https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/builtin-types/struct#readonly-struct)
They also have "records" which are immutable class-like objects with
language support for cloning using `with().`
https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/builtin-types/record
... these "records" can inherit from each other, but a regular class
cannot inherit from a record and vice-versa.

Robert Landers
Software Engineer
Utrecht NL

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: https://www.php.net/unsub.php

Reply via email to