Re: [RFC] Immutable variables and objects

From: Date: Sun, 01 Feb 2015 18:50:49 +0000
Subject: Re: [RFC] Immutable variables and objects
References: 1 2 3 4 5  Groups: php.internals 
Request: Send a blank email to [email protected] to get a copy of this message
On 01/02/2015 01:06, Andrea Faulds wrote:
the intermediate objects are useless and nobody needs 5 new objects when
you do it. Am I missing something here? I assume the reason for doing this is so you can’t ever modify the object from a distance, you must always create a new one to avoid messing up anything with an existing handle on it.
An alternative, which I'm guessing FIG considered and rejected, is having a mutable "builder" object, and require the user to specifically request an immutable object when they're ready to use it: $builder = new RequestBulider; $a = $builder->withHeaders(...)->withBody(...)->getRequest(); $a_prime = $builder->withEncoding(...)->withETag(...)->getRequest(); -- Rowan Collins [IMSoP]

Thread (23 messages)

« previous php.internals (#81539) next »