Hi Everyone, After quite a long pause, I'd like to revive the discussion of readonly classes and possibly put it to vote in the coming week(s).
If I'm following, then this RFC is about 90% syntactic sugar for putting > `readonly` on all properties, plus disabling dynamic properties. That's > the long-and-short of it, yes? > Yes, exactly! > Does disabling dynamic properties offer any other advantages as have been > discussed otherwise recently? (E.g., performance.) > No, I'm not aware of any other advantages. The only reason why I included this feature into the current RFC is because otherwise a readonly class wouldn't be readonly. :) The same applies for forbidding the declaration of static properties. Is there a way to opt a given property back OUT of being readonly, or if > you have a readonly class and need to add a single mutable property to it > are you stuck adding `readonly` to all existing properties first? (I'm not > sure I'm suggesting having such a mechanism, mostly just clarifying.) > Yes, you are right. This is an inconvenient situation for sure, but neither I can imagine any other way to back a property out of being readonly than to remove the readonly class modifier + add readonly property modifier where possible. Of course, the readonly property modifier doesn't apply to the internal state of objects... so doing the above is not necessary if you have to modify a readonly property which is an object. > It's interesting that this also provides a backdoor way to force all > properties to be typed, as a side effect. However... that also means you > cannot mark a class readonly if any of its properties are callables, since > callables cannot be typed. (I guess you could use mixed and then docblock > callable, which is a bit fugly but not a problem introduced by this RFC.) Yeah, you are right, an ugly hack is to use the mixed type for properties that cannot be typed otherwise (e.g. resource). I believe in case of callables, one could use the Closure type instead, especially since the first-class callable syntax has been introduced. I hope I managed to address your questions/concerns. Máté