re: Introducing strong native PHP types VIEW POST

TOP OF THREAD FULL DISCUSSION
re: why did you choose to have the mutable option? It looks like that you can do everything you need with the immutable version, and get more type safety
 

Thanks for the reply.

I’m not sure I understand your question. When you make a type immutable, you can’t change its value. So, utility methods will trigger an exception. All you can do is change its type.

If a type is mutable, you can modify its value, as well as convert it to another type.

 

The point was not the meaning of mutability/immutability. The point was that mutability makes the whole typing weaker, and IMHO should be avoided if possible.

It would be safer to have everything immutable and just return new values (with clone) instead of modifying the current ones

After further thought, I agree and have released an updated version (2.0) that makes all utility methods return new instances, thus providing immutability.

code of conduct - report abuse