Thanks Paul, I do have rough idea how to go about arrays possibly without recursive scan, I have to try couple of things, it could work if some checks are moved to zval level. For now it is in the future scope unless I manage to handle the within week or two.
First two proposals are valid points. Regarding disabling constructor, that would fail as soon as you try to write properties in constructor since object is already "locked". Best regards and thanks for proposals. 2018-02-23 15:08 GMT+01:00 Paul Jones <pmjone...@gmail.com>: > 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 > pmjo...@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 > > > > -- Silvio Marijić Software Engineer SMSGlobal