Re: Immutable modifier

From: Date: Mon, 16 Nov 2015 10:00:49 +0000
Subject: Re: Immutable modifier
References: 1 2 3  Groups: php.internals 
Request: Send a blank email to internals+get-89229@lists.php.net to get a copy of this message
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" <mailto.woden@gmail.com> 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 <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 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


« previous php.internals (#89229) next »