On 16 November 2015 at 09:24, Daniel Persson <[email protected]> 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 <[email protected]> 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 >> > > Yes, final prevents child classes from overriding a method or from extending a class entirely, this is a compile time constraint. Immutable prevents data modifications and as such is a run time constraint. ~C
