Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:89229 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 58153 invoked from network); 16 Nov 2015 10:30:44 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 16 Nov 2015 10:30:44 -0000 Authentication-Results: pb1.pair.com header.from=mathieu@rochette.cc; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=mathieu@rochette.cc; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain rochette.cc designates 195.154.14.121 as permitted sender) X-PHP-List-Original-Sender: mathieu@rochette.cc X-Host-Fingerprint: 195.154.14.121 texthtml.net Received: from [195.154.14.121] ([195.154.14.121:33293] helo=texthtml.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id D1/20-52418-759A9465 for ; Mon, 16 Nov 2015 05:00:57 -0500 Received: by texthtml.net (Postfix, from userid 99) id 27891101F84; Mon, 16 Nov 2015 10:51:08 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on texthtml.net X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from [192.168.1.130] (localhost [127.0.0.1]) by texthtml.net (Postfix) with ESMTPA id 30DEE101F80; Mon, 16 Nov 2015 10:51:06 +0100 (CET) To: Lorenzo Fontana , Daniel Persson References: Cc: internals@lists.php.net, Chris Riley Message-ID: <5649A951.80707@rochette.cc> Date: Mon, 16 Nov 2015 11:00:49 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.3.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] Immutable modifier From: mathieu@rochette.cc (Mathieu Rochette) hi, On 16/11/2015 10:33, Lorenzo Fontana wrote: > I really like the concept of immutability, but I think that it should be > applicable at instance level rather than declaration. I'm not sure about that, most PHP code assume mutable objects, I doubt much existing classes would be usable as immutable > > I would also prefer another keyword than immutable. > > Final does not make the properties immutable, it makes the class not > extensible. > On Nov 16, 2015 10:24, "Daniel Persson" wrote: > >> Any differance from the final keyword? >> >> http://php.net/manual/en/language.oop5.final.php >> >> On Mon, Nov 16, 2015 at 10:15 AM, Chris Riley wrote: >> >>> Hi, >>> >>> There has been a lot of interest recently (eg psr-7) in immutable data. >> I'm >>> considering putting an RFC together to add language support for >> immutables: >>> immutable class Foo { >>> public $bar; >>> public function __construct($bar) { >>> $this->bar = $bar; >>> } >>> } >>> >>> Immutable on a class declaration makes all (maybe only public?) >> properties I don't think it's enough to make only public properties immutable. this would lead to a lot of mutable "immutable" classes, eg: immutable class my_class { private $my_prop; __construct($my_prop) { $this->my_prop = $my_prop; } public function getMyProp() { return $this->my_prop; } public function setMyProp($my_prop) { return $this->my_prop = $my_prop; } } how is this class immutable ? also, what about __isset/__set ? Would it be allowed to assign non immutable types to properties of an immutable class ? >>> of the class immutable after construct; assigning to a property would >>> result in a Fatal error. >>> >>> class Foo { >>> public $bar; >>> immutable public $baz; >>> } >>> >>> Immutable on a property makes the property immutable once it takes on a >>> none null value. Attempts to modify the property after this results in a >>> fatal error. >>> >>> Any thoughts? >>> ~C >>>