Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:95564 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 34817 invoked from network); 2 Sep 2016 14:06:10 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 2 Sep 2016 14:06:10 -0000 Authentication-Results: pb1.pair.com smtp.mail=marijic.silvio@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=marijic.silvio@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.214.43 as permitted sender) X-PHP-List-Original-Sender: marijic.silvio@gmail.com X-Host-Fingerprint: 209.85.214.43 mail-it0-f43.google.com Received: from [209.85.214.43] ([209.85.214.43:37541] helo=mail-it0-f43.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id C5/96-19490-05789C75 for ; Fri, 02 Sep 2016 10:06:08 -0400 Received: by mail-it0-f43.google.com with SMTP id e124so39331502ith.0 for ; Fri, 02 Sep 2016 07:06:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=Pg7AijLngqsuAvJEq/EWrvT31YgLL56d5pez5MI/WyQ=; b=de4JyrxTUn5Mzi2g8tAxWhoRUaRsmhWW0OypDfzXTAfrYMJTmQn26Rhu9mUpZYgrwZ /9Mi2YJRuMtMxaZ/Bbk+t7MkbXOPjFONsjRPjUkhXGl2FpunGEVfwRIGWlAg3yCYdCX4 5tQ2s6o35sW/7GAgKfpNMmU+CA+Xs/bR7618gAFB7+YKd6KSZGpEGiy714OgzxdfzBIE Uy/2vtJwmBS3k4UJIPQo04VknqY7q87sHyw1yi/99OD6QehxKlk0+1+EHY8Ns1VivUix i5OVpUoB2nPEGWNidzwxrtJD+TFMnwp3lB+/MQOxAOgpbnVDIjlMcIpYvs5kKY0TTu+5 5K3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=Pg7AijLngqsuAvJEq/EWrvT31YgLL56d5pez5MI/WyQ=; b=XHevLaNCa8ZUZs7oSDSHXUL+aI1+/oOhswpt6O0SzsdlqWdNb+G5kImjzloSi8BDK1 73QCj5nVEdOOgk8gMaPywB7Hd6zDNUQyRCZRpJvwgxJ6maLSNyflI4SyZu1OL3AcjV9A X3Li4aaAdB1fpMqFWMXglCINtDTmzNIy+8hWpI+rESmTZKWWhG7I7hfy7yOwxzd/NN9m 5/0gWIEjmOHJjnEZtr4gQcHGukBmubDwP2NH6+Cn76XnKRlyjQzYvuCdtTYcGSQsWid7 mdlCiOL7GX6Ll13F7Vvax5wJpqLr4eBXsjqVlKWBvadvpvrYz8y/zZ64vicz9RJojxZH pRFA== X-Gm-Message-State: AE9vXwNNmUosqxD+9f4JtE9xy3iz92GU8d42dzzofy3F8TKhaVnKV+3sa+v35vkC3pvxia/e2D+MDVg5sO0rdw== X-Received: by 10.36.95.1 with SMTP id r1mr5284793itb.6.1472825164975; Fri, 02 Sep 2016 07:06:04 -0700 (PDT) MIME-Version: 1.0 Received: by 10.36.237.74 with HTTP; Fri, 2 Sep 2016 07:06:04 -0700 (PDT) In-Reply-To: References: <167d6432-e4d6-d87d-5d31-d3d82a8de4ce@fleshgrinder.com> <99F80C06-654D-4109-BE07-2FA5B1073E5D@ez.no> <4f54308a-4a69-2e6b-2ed0-51d4336d1cd4@fleshgrinder.com> <5969d1af-48e5-1376-07fe-9568de538145@texthtml.net> Date: Fri, 2 Sep 2016 16:06:04 +0200 Message-ID: To: =?UTF-8?B?QW5kcsOpIFLDuG1ja2U=?= Cc: =?UTF-8?Q?Micha=C5=82_Brzuchalski?= , Mathieu Rochette , PHP Internals List , Fleshgrinder Content-Type: multipart/alternative; boundary=001a1144981ec6848d053b86d437 Subject: Re: [PHP-DEV] RFC - Immutable classes From: marijic.silvio@gmail.com (=?UTF-8?Q?Silvio_Mariji=C4=87?=) --001a1144981ec6848d053b86d437 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Well at the moment expection is thrown in case when you try to clone immutable object. But you do seem to have valid point there regarding __clone method. I'm definitely going to give it a thought. Best, Silvio. 2016-09-02 15:52 GMT+02:00 Andr=C3=A9 R=C3=B8mcke : > > > > On Sep 2, 2016, at 09:10 , Silvio Mariji=C4=87 > wrote: > > > > Hi Fleshgrinder, > > > > Since Michal answered most of the questions, I'll just add some notes. > > Initially I added restrictions to abstract classes, but I did think abo= ut > > that over the last couple of days and couldn't find any concrete reason > for > > that restriction, so I think I'm going to remove that. As far as clonin= g, > > it is disabled for immutable objects, because you'll end up with the co= py > > of object that you can not modify. I did mention in Cons sections that > > cloning is disabled, maybe it should be made more clear. > > > _If_ there are use-cases for it, wouldn=E2=80=99t it also be safe that th= e clone > is allowed to be modified during __clone() and afterwards sealed? Like in > __construct(). > And if you don=E2=80=99t want to allow cloning, throw in __clone. > > Best, > Andr=C3=A9 > > > > > > Best, > > Silvio. > > > > 2016-09-02 4:23 GMT+02:00 Micha=C5=82 Brzuchalski : > > > >> Firstly, thanks for your interest. > >> My answers are inline. > >> > >> 2016-09-01 23:48 GMT+02:00 Mathieu Rochette : > >> > >>> > >>> > >>> On 09/01/2016 09:12 PM, Fleshgrinder wrote: > >>>> On 9/1/2016 3:49 PM, Silvio Mariji=C4=87 wrote: > >>>>> Hi Andre, > >>>>> > >>>>> Here is RFC https://wiki.php.net/rfc/immutability and you have link > >> to > >>>>> implementation github. Any suggestions and feedback are more then > >>> welcome. > >>>>> > >>>>> Best, > >>>>> Silvio > >>>>> > >>>> Hi Silvio, > >>>> > >>>> very nice work you guys did here! :) > >>> indeed! nice to see this going forward > >>>> > >>>> Abstract classes are not mentioned at all in the RFC. However, there > is > >>>> a test case from which it is clear that abstract classes cannot be > >>>> immutable. Are there any reasons for this restrictions? > >>>> > >>>> What about array and resource values? Not mentioned in the RFC. > >>> I guess they are not authorized in immutable classes as they are not > >>> immutable themselves, but I think it could be explained > >>> > >> > >> Yes that could be explained, they are actually not authorized because = we > >> cannot guarantee developer will use them internally only. So in case > this > >> property will interact with immutable object state should be also > >> immutable. > >> > >> > >>>> > >>>> The fact that cloning is not possible should also be extended in the > >>>> RFC. I mean, it's clear to me but maybe not to others. Remember that > >> the > >>>> RFC is the main source of information for the feature (e.g. to > generate > >>>> documentation). > >>> agreed, I don't get why it's not possible :/ > >>>> > >>> > >> > >> I think any RFC enchancements in this area is welcome. > >> > >> > >>>> Why the restrictions that all properties of an immutable class that > >> take > >>>> objects must be immutable too? It's clear why an immutable property > >> must > >>>> contain an immutable class but the inheritance from the class to the > >>>> properties is not consistent with how things work. An immutable clas= s > >>>> might want to contain an internal cache (e.g. flyweight pattern). > >>>> > >>>> immutable final class Flyweight { > >>>> > >>>> private static $instances =3D []; > >>>> > >>>> public immutable $value; > >>>> > >>>> private function __construct($value) { > >>>> $this->value =3D $value; > >>>> } > >>>> > >>>> public static function ENUM_ORD() { > >>>> if (isset(self::$instances[1]) =3D=3D=3D false) { > >>>> self::$instances[1] =3D new self(1); > >>>> } > >>>> > >>>> return self::$instances[1]; > >>>> } > >>>> > >>>> } > >>>> > >>>> $o1 =3D Flyweight::ENUM_ORD(); > >>>> $o2 =3D Flyweight::ENUM_ORD(); > >>>> > >>>> var_dump($o1 =3D=3D=3D $o2); // bool(true) > >>> I can understand the usecase, but then, how could the language ensur= e > >>> the class is immutable > >> > >> > >> It cannot be ensured while non-immutable property will exists in > immutable > >> object. > >> > >> > >>> side note: what about access (read & write) to undefined properties ? > >>> > >> > >> You mean properties which are declared and default null and never > changed > >> during object instantiation? > >> > >> > >>>> > >>>> Note that we could add the restriction that an immutable class that > >>>> should be used in a threading context must contain only immutable > >>>> properties in the future when the need arises. However, for now I do > >> not > >>>> see the need to inherit the modifier from the class to its propertie= s > >>>> and I see use cases where the developer wants more control. > >>> > >> > >> We agreed that it would be best for ensuring the object state is > immutable > >> (that implies it can be deeply frozen for writes as deep as all his > >> properties > >> and properties object properties etc.) > >> > >> > >>>> > >>>> The test cases cover the most stuff but not everything and could be > >>>> extended. There are other things with the PR but I will check it out > >> and > >>>> create a PR against your branch with that so you can review it. (Mig= ht > >>>> take a while so bare with me.) > >>>> > >>> > >>> The RFC contains several grammatical issues. I could help you with th= at > >>>> too if you want. > >>>> > >>> > >> > >> As abowe any RFC enchancements are welcome :) > >> > >> > >>>> There is a lot of diff noise in the ext/tokenizer/tokenizer_data.c > >> file. > >>>> > >>> > >>> -- > >>> Mathieu Rochette > >>> > >>> > >>> -- > >>> PHP Internals - PHP Runtime Development Mailing List > >>> To unsubscribe, visit: http://www.php.net/unsub.php > >>> > >>> > >> > >> > >> -- > >> regards / pozdrawiam, > >> -- > >> Micha=C5=82 Brzuchalski > >> brzuchalski.com > >> > > > > > > > > -- > > Silvio Mariji=C4=87 > > Software Engineer > > 2e Systems > > --=20 Silvio Mariji=C4=87 Software Engineer 2e Systems --001a1144981ec6848d053b86d437--