Mathieu Rochette wrote on 17/11/2015 13:40:
Indeed, maybe there is a use for a new language construct to help reduce the boilerplate, but it could be done afterward, the "everything in the constructor" works fine. If there is too much in the construct it might be a sign that the class is doing too much and should be refactored in smaller classes

Even with a small number of members, manually reconstructing the object is a nuisance - imagine if you have 4 properties, and 10 "with" methods; not particularly complex for one class. But with "mutable only in the constructor", adding a 5th property would require changing all 10 methods, for absolutely zero gain.

It's certainly doable, and if the clone keyword didn't already exist, it would be a reasonable thing to do; but the gains of using "clone" (in terms of code readability and robustness) rather outweigh the gains of marking the class immutable, if the implementation is such that you're forced to choose.

Regards,
--
Rowan Collins
[IMSoP]

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

Reply via email to