Nicolas Grekas wrote:

> But I'm also wondering about the use case where asymmetry would be
> useful in practice now that we have readonly?
> I voted against readonly at the time because it didn't address
> cloning, and also because it deprives end-users vs code authors IMHO
> (alike "final"). I would have very much prefered asymmetric
> visibility back then. But now that we are here, what are the use cases?

Isn't it (obviously?) to have setters that ensure all invariants of the
properties are met? I'd still rather have Property Accessors as
described in https://wiki.php.net/rfc/property_accessors, but I think
AV is a step in the right direction.

As for readonly, I don't understand why that exists at all. Yes, it's
good that readonly properties can only be set from within the class,
but only once, so you get setters that throw when called a second time,
which I think is very, VERY unexpected behavior. Calling them
"readonly" is also somewhat misleading because of course the objects
assigned to those "readonly" properties can still be mutated, they can
just not be reassigned.

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

Reply via email to