The `final` modifier would likely clash with property type definitions, if
those ever make it to the language.

Still, a few pain-points remain:

 * References to properties (you cannot reference final properties anymore,
and that is effectively a BC break for anything using reflection and
closure scope binding)
 * Arrays and resources as properties
 * Named (Factory) constructors
 * Property nullability - how do you define if a property was written to
the "last valid time" before freezing it
 * Unset properties and providing an alternative mechanism to distinguish
"uninitiated",  "undefined" and "frozen" in he event of final properties
usage, without breaking current property access semantics

This is the exact same set of problems we had with the typed properties
RFC, and which caused the RFC to fail: please take all these in
consideration while designing the feature.

On 29 Jun 2017 4:57 AM, "Kalle Sommer Nielsen" <ka...@php.net> wrote:

> 2017-06-29 1:07 GMT+02:00 David Rodrigues <david.pro...@gmail.com>:
> >   readonly $number = mt_rand();
> > I agree that "readonly" is a better keyword, but we have to points here:
> > 1. "final" is used on some language (Java, C++ I guess);
> > 2. "final" keyword does exists on PHP with a "similar" behaviour;
>
> > If we can implements "readonly" is good too, because turn it more
> implicit.
> True we could re-use the final keyword, but think about it this way,
> we got final methods and final classes which means it cannot be
> overridden/extended respectively, if the final keyword then would also
> apply to variables but it would mean they could not be written to,
> that would create a WTF-factor.
>
> The readonly keyword would work for any visibility modifiers, so
> inherited classes or extending classes may read a protected property,
> but not modify it as well:
>
> class A {
>  protected readonly $b;
>
>  public function __construct() {
>   $this->b = 'C';
>  }
> }
>
> class B extends A {
>  public function read() {
>   echo $this->b;
>  }
>
>  public function write() {
>   $this->b = 'D';
>  }
> }
>
> $b = new B;
>
> $b->read(); // "C"
> $b->write(); // <- error
>
>
> --
> regards,
>
> Kalle Sommer Nielsen
> ka...@php.net
>
> --
> PHP Internals - PHP Runtime Development Mailing List
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

Reply via email to