Re: RFC - Immutable classes
| From: | Fleshgrinder | Date: | Thu, 15 Sep 2016 18:58:59 +0000 |
| Subject: | Re: RFC - Immutable classes | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-96009@lists.php.net to get a copy of this message | ||
On 9/14/2016 7:25 PM, Mathieu Rochette wrote:
> yeah the example is not that great, I'll usually want to clone to
> avoid calling a constructor with to many parameters (or a constructor
> doing too many things not needed here)
>
That's exactly the reason why we want the _clone_ modifier. :)
On 9/14/2016 7:25 PM, Mathieu Rochette wrote:
> what's the difference between the two for an immutable class?
>
The difference is that the engine cannot reason whether you need a clone
now or not. Allowing cloning in any context directly results in the fact
that someone from the outside can receive a copy of the object that is
actually mutable. However, exactly that is what we want to avoid by all
means.
It's true that userland deep cloning implementations will need to check
whether the instance at hand is cloneable or not. But as a matter of
fact they need to do that already anyways because there is no guarantee
that an object is actually cloneable because the
Attachment: [application/pgp-signature] OpenPGP digital signature signature.asc
__clone callback
could be invisible (protected/private) already.
--
Richard "Fleshgrinder" Fussenegger
Attachment: [application/pgp-signature] OpenPGP digital signature signature.asc