Hello internals,

Java supports the "final" keyword before a variable to determines that this
variables never change it reference. If I declare a variable as "final", I
can only initialize that once, then I could not change it after (but I can
manipulate the instance, without issues).

There some special reason to PHP doesn't supports things like that?

final $number = 123;
$number = 456; // Error: you change change final variables.

final $object = new stdClass;
$object->allowed = true; // No error.

This feature make sense because it tells to dev that the variable value
could not be updated directly (new reference). Which make easy to identify
when a variable is modifiable or not.

It is valid for a RFC?

- It can uses the "final" keyword;
- It doesn't a BC;

I too think that a final variable can be useful to make some internal
improvements on language (but it could be a BC for PHP internals). I mean,
as the variable could not be modified, then it don't need be a "flexible"
type internally (I guess that it is a zval, right?).

Reference: https://github.com/kalessil/phpinspectionsea/issues/363

-- 
David Rodrigues

Reply via email to