Re: [RFC] Immutable variables and objects
| From: | Stanislav Malyshev | Date: | Sun, 01 Feb 2015 00:55:17 +0000 |
| Subject: | Re: [RFC] Immutable variables and objects | ||
| References: | 1 2 3 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-81509@lists.php.net to get a copy of this message | ||
Hi!
> The with*() methods in PSR-7 are documented to return a new instance,
> not modify the existing instance. Yes, there's no way in PHP itself to
> force that syntactically, which is why documentation exists. :-)
>
> Also, in the benchmarks we've run the performance cost of all those new
> objects is measured in nanoseconds, ie, small enough that we're not
> worried about it. (Hats off to the PHP Internals folks for making that
> fast!)
It is great that this is fast, but I wonder (maybe off-topic?) why do
it? I.e. it is clear that in something like:
$a = new Request->withHeaders(...)->withBody(...)
->withEncoding(...)->withETag(...)
the intermediate objects are useless and nobody needs 5 new objects when
you do it. Am I missing something here?
--
Stas Malyshev
smalyshev@gmail.com