On Tue, May 28, 2013 at 10:58 AM, Lars Strojny <l...@strojny.net> wrote:

> Hi Ferenc,
>
> Am 28.05.2013 um 08:15 schrieb Ferenc Kovacs <tyr...@gmail.com>:
> [...]
> >> I would like it to work the same way as it does in java(
> >> http://docs.oracle.com/javase/specs/jls/se7/html/jls-4.html#jls-4.12.4)
> >> eg. you can set the initial value either in the declaration or later on,
> >> but after it is set, you can't change it, trying to do that would
> create a
> >> recoverable fatal error (or throwing an exception which extends
> >> RuntimeException).
> >>
> >> What do you think? Would this be viable? Is there any still-present
> reason
> >> why we shouldn't support that?
> [...]
> > the accessors rfc got rejected, so I'm bringing this up again.
>
> 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
>
> cu,
> Lars


I think that this proposal only makes sense in a class context.
For your example we already have a solution: constants.
Unfortunately class constants has more limitation, as you can't assign
expressions to them, and using global(namespaced) constants which will be
only used in that class breaks the encapsulation part of OOP, as your
constants are "leaking" out.
One solution would be to allow the class consts to accept expressions, but
for that the simple solution would slow down the class constanst for
everybody.

-- 
Ferenc Kovács
@Tyr43l - http://tyrael.hu

Reply via email to