Re: Immutable modifier

From: Date: Mon, 16 Nov 2015 23:39:57 +0000
Subject: Re: Immutable modifier
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-89249@lists.php.net to get a copy of this message
On Mon, Nov 16, 2015 at 2:15 AM, Chris Riley <t.carnage@gmail.com> 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 > In my opinion we should just generalize const for this, rather than add a new keyword.

« previous php.internals (#89249) next »