Re: [RFC][DISCUSSION] Immutability

From: Date: Fri, 23 Feb 2018 14:08:20 +0000
Subject: Re: [RFC][DISCUSSION] Immutability
References: 1 2 3 4 5  Groups: php.internals 
Request: Send a blank email to internals+get-101908@lists.php.net to get a copy of this message
Hi Silvio, I like the RFC. * * * I would like to see arrays allowed as immutable properties. In <http://paul-m-jones.com/archives/6400> I wrote that arrays are "probably not practical in most situations" because you have to "recursively scan through array properties to make sure that they contain only immutable values". However, I think if the scanning happens at the C level it is not such a burden. John Boehr implemented it for the immutable ServerRequest object in ext-request <http://pecl.php.net/package/request> and it has worked well. If you do allow arrays, they would have to follow the same rules as the immutable object. Alternatively, perhaps an ImmutableArrayObject would be a good addition or followup to the RFC. * * * Some further points to harden the implementation: - I see that resources and references are disallowed (which is good). If you have not already done so, you may wish to disallow streams as well. - You might want to disable setting of undefined public properties, so that you cannot "add" mutable public properties to the immutable object. - Disable the constructor after it has been called, so the object cannot be "re-constructed" in place. * * * That's all I can think of for now. Thanks for putting this together. -- Paul M. Jones pmjones@pmjones.io http://paul-m-jones.com Modernizing Legacy Applications in PHP https://leanpub.com/mlaphp Solving the N+1 Problem in PHP https://leanpub.com/sn1php

« previous php.internals (#101908) next »