On Mon, Feb 24, 2020, 09:19 Rowan Tommins <rowan.coll...@gmail.com> wrote:
> On 24 February 2020 03:26:19 GMT+00:00, Marco Pivetta <ocram...@gmail.com> > wrote: > >The solution is trivial: don't use cloning: > > > >final class Foo > >{ > > public function withBar($bar):self { > > $instance = new self(); > > $instance->foo = $foo; > > // more assignments here - unavoidable > > return $instance; > > } > >} > > > This works fine on paper, but is completely impractical as the class > grows. Consider a class with 10 such properties Yes, considered it: it's fine. Also, the best approach would be to have a ctor with those 10 properties. It's also impossible to use with inheritance, or to compose with traits (as > Diactoros does, for instance) Inheritance would be ditched in favour of even more composition, but even then, inheritance is not a massive issue, especially when it comes to value types. Probably a couple hours of work to make a full PSR-7 implementation with the old tests running, and the new approach applied 👍 For things that are more sensible, like a UUID, a Domain Event or a Command, this is really a game changer anyway. The good old Object Calisthenics rules do really apply.