> On Aug 11, 2022, at 7:38 PM, André Hänsel <an...@webkr.de> wrote:
> 
> 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.


For immutability. 

Here is one reference on immutability offered up by the google gods:

https://hackernoon.com/5-benefits-of-immutable-objects-worth-considering-for-your-next-project-f98e7e85b6ac
 
<https://hackernoon.com/5-benefits-of-immutable-objects-worth-considering-for-your-next-project-f98e7e85b6ac>

Immutability goes hand-in-hand with Functional Programming (FP.)  While PHP is 
not a functional programming language,  PHP developers can gain benefits from 
an FP style for which immutability is beneficial. 

Also from the google gods, if you are unfamiliar with FP:

https://alvinalexander.com/scala/fp-book/benefits-of-functional-programming/ 
<https://alvinalexander.com/scala/fp-book/benefits-of-functional-programming/> 

Hope this helps.

-Mike

P.S. Also, the Internals list's very own Larry Garfield is a huge advocate for 
FP in PHP, voilà:

https://leanpub.com/thinking-functionally-in-php
https://www.garfieldtech.com/taxonomy/term/95


> 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