Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:89227 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 50936 invoked from network); 16 Nov 2015 09:40:15 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 16 Nov 2015 09:40:15 -0000 Authentication-Results: pb1.pair.com header.from=t.carnage@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=t.carnage@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 74.125.82.46 as permitted sender) X-PHP-List-Original-Sender: t.carnage@gmail.com X-Host-Fingerprint: 74.125.82.46 mail-wm0-f46.google.com Received: from [74.125.82.46] ([74.125.82.46:36605] helo=mail-wm0-f46.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 47/A0-46953-C74A9465 for ; Mon, 16 Nov 2015 04:40:12 -0500 Received: by wmww144 with SMTP id w144so101836676wmw.1 for ; Mon, 16 Nov 2015 01:40:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=5t60+AfTU2e/Xv8G436t5xDM6CtmAKsjGkRpcd6wFVI=; b=BWD9VqohGMksu9eoMFO+y196M6Y1nIaA++Jv+FTVdCG4mj0wbqlm0maWJ31WwuF4lz 6S7EQVZwmrxwjgfe9lWgX9CT/0epwQV3rSPtsvuZXJ21/YBPmF4SjENYO3d5z/rBojUl u7gjpx255xi9B5Y/+Oz25B0GYNxpqUbUJsWukeaR2x9CJmGB+KQmcc4OROWZdol/qsna Wk+ky04v11Bx/z5tGYq5Tr4HpaRtjARiYtcQOi6JJeZm+75b+yZKrIH0920ayLjvQDxm P+/yY0q7zTL2wliz8ut+1i01mxCyj29IqC3MxxPhd46X1ttVppcn4HHzOvIcN1ALgS5v u7QQ== MIME-Version: 1.0 X-Received: by 10.28.1.8 with SMTP id 8mr2375576wmb.40.1447666808964; Mon, 16 Nov 2015 01:40:08 -0800 (PST) Received: by 10.27.130.149 with HTTP; Mon, 16 Nov 2015 01:40:08 -0800 (PST) In-Reply-To: References: Date: Mon, 16 Nov 2015 09:40:08 +0000 Message-ID: To: Lorenzo Fontana Cc: Daniel Persson , PHP internals Content-Type: multipart/alternative; boundary=001a113d52e2e6d2140524a5314a Subject: Re: [PHP-DEV] Immutable modifier From: t.carnage@gmail.com (Chris Riley) --001a113d52e2e6d2140524a5314a Content-Type: text/plain; charset=UTF-8 On 16 November 2015 at 09: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 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 >> > 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 >> > >> > What instance level syntax would you propose? $foo = new immutable bar(); ? or immutable $foo = new bar(); Gives less flexibility imo and less guarantees of correctness. Consider the current user land implementation of immutable classes: class Foo { private $bar; public function __construct($bar) { $this->bar = $bar; } public function getBar() { return $this->bar; } } Is already done at declaration declaration based immutability is probably more desirable. What keyword would you suggest other than immutable? ~C --001a113d52e2e6d2140524a5314a--