Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:95547 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 46788 invoked from network); 1 Sep 2016 21:49:07 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 1 Sep 2016 21:49:07 -0000 Authentication-Results: pb1.pair.com smtp.mail=mathieu@texthtml.net; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=mathieu@texthtml.net; sender-id=pass Received-SPF: pass (pb1.pair.com: domain texthtml.net designates 62.210.206.189 as permitted sender) X-PHP-List-Original-Sender: mathieu@texthtml.net X-Host-Fingerprint: 62.210.206.189 texthtml.net Received: from [62.210.206.189] ([62.210.206.189:56245] helo=texthtml.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id C0/87-47600-F42A8C75 for ; Thu, 01 Sep 2016 17:49:04 -0400 Received: by texthtml.net (Postfix, from userid 65534) id B58E16A5; Thu, 1 Sep 2016 21:49:00 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on a05d8528c5e6 X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED autolearn=ham autolearn_force=no version=3.4.1 Received: from [192.168.0.101] (stunnel_mail_1.mail_default [172.29.0.4]) (Authenticated sender: mathieu@texthtml.net) by texthtml.net (Postfix) with ESMTPA id 9CB1F6A2; Thu, 1 Sep 2016 21:48:44 +0000 (UTC) To: internals@lists.php.net, Fleshgrinder References: <167d6432-e4d6-d87d-5d31-d3d82a8de4ce@fleshgrinder.com> <99F80C06-654D-4109-BE07-2FA5B1073E5D@ez.no> <4f54308a-4a69-2e6b-2ed0-51d4336d1cd4@fleshgrinder.com> Message-ID: <5969d1af-48e5-1376-07fe-9568de538145@texthtml.net> Date: Thu, 1 Sep 2016 23:48:43 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:50.0) Gecko/20100101 Thunderbird/50.0a2 MIME-Version: 1.0 In-Reply-To: <4f54308a-4a69-2e6b-2ed0-51d4336d1cd4@fleshgrinder.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Content-Language: en-US Subject: Re: [PHP-DEV] RFC - Immutable classes From: mathieu@texthtml.net (Mathieu Rochette) On 09/01/2016 09:12 PM, Fleshgrinder wrote: > On 9/1/2016 3:49 PM, Silvio Marijić 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 > > 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 :/ > > 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 class > might want to contain an internal cache (e.g. flyweight pattern). > > immutable final class Flyweight { > > private static $instances = []; > > public immutable $value; > > private function __construct($value) { > $this->value = $value; > } > > public static function ENUM_ORD() { > if (isset(self::$instances[1]) === false) { > self::$instances[1] = new self(1); > } > > return self::$instances[1]; > } > > } > > $o1 = Flyweight::ENUM_ORD(); > $o2 = Flyweight::ENUM_ORD(); > > var_dump($o1 === $o2); // bool(true) I can understand the usecase, but then, how could the language ensure the class is immutable side note: what about access (read & write) to undefined properties ? > > 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 properties > and I see use cases where the developer wants more control. > > 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. (Might > take a while so bare with me.) > > The RFC contains several grammatical issues. I could help you with that > too if you want. > > There is a lot of diff noise in the ext/tokenizer/tokenizer_data.c file. > -- Mathieu Rochette