Re: [RFC] Immutable variables and objects
| From: | Rowan Collins | 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 internals+get-81539@lists.php.net to get a copy of this message | ||
On 01/02/2015 01:06, Andrea Faulds wrote:
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]the intermediate objects are useless and nobody needs 5 new objects whenyou 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.