Re: supporting the final keyword for properties

From: Date: Tue, 28 May 2013 09:26:55 +0000
Subject: Re: supporting the final keyword for properties
References: 1 2 3 4 5  Groups: php.internals 
Request: Send a blank email to internals+get-67581@lists.php.net to get a copy of this message
2013/5/28 Amaury Bouchard <amaury@amaury.net> > 2013/5/28 Maciek Sokolewicz <maciek.sokolewicz@gmail.com> > > > It’s a good idea in general but what about having it for variables as > >> well? Could open interesting possibilities for an optimizer. > >> > >> final $foo = "str"; > >> $foo = "bar"; // bails out > >> > >> Don't we already have that? It just has a different name: constants. > > > It's different. You can manipulate variables in some ways you can't with > constants. > > This code, for example: > $a = 'abc'; > $b = 'a'; > print($$b); > > It will display "abc". It's currently not possible to do something similar > with constants. > define('FOO', 'bar'); $b = 'FOO'; print(constant($b)); and yes, constant() works for namespace- and class-constants too. > > I think the subject was already debated, but I wonder why we should write > that: > final $foo = 'bar'; > instead of: > const $foo = 'bar'; > -- github.com/KingCrunch

« previous php.internals (#67581) next »