I will try answer the questions:

> I get that, but I still don't understand why you would forcefully need
> it to be a variable still then if you know the value is gonna be
> constant, of course besides global visibility or in iterations

"final" is not "const". "final" mean a initial state that will never be
modified, but it could be initialized with different values on same
runtime. It is like I say "my name is David and will be all the time David
when I am on an informal context" and "my name is Rodrigues and will be all
the time Rodrigues when I am on a forma context", on same "document".
https://pastebin.com/QCrmrZQe

> 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.

It is done on Java, for instance. We can use "final" on classes or
functions that mean that it cannot be overrided, or "final" in variables,
that mean that it cannot be re-referenced (rewrite after initialization).
And not seems strange to me. We could "abstract the term" to understand
that in any of cases (for classes, function or variables) the information
could not be overrided after defined.

> 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:

For me, the readonly keyword should be implemented on future to another
case: make a public property writeable only by the own class. But it is for
another discussion.

> 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)

I don't know if I understand, but for properties you could redefine a final
property on constructor (as Java). https://pastebin.com/bTZcUT33

>  * Arrays and resources as properties

You can modify arrays or resources on final variables, since that you don't
modify the reference. https://pastebin.com/D38wL8x7

>  * Named (Factory) constructors

I don't understand.

>  * Property nullability - how do you define if a property was written to
the "last valid time" before freezing it

Because PHP don't have support to "variable initialization" (eg. "$name;")
then you should only initializate it when you will write the initial (and
freezed) value. https://pastebin.com/Ua6DFUC1

 > * 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

It will be modified. Final variables still are a variable, but with the
status that "never change after initializate" (a flag). We can just
implement a new reflection method to properties to identify if it
isFinal(), or even for variables like "is_final($var)". By other side, this
last doesn't make sense because the final variable is just a "code
documentation" to the own dev knows that is not allowed modify it anymore.
Maybe we need implements that only for ReflectionProperty (first case),
because it could be part of a code that the user have not modify access
(eg. vendor code). https://pastebin.com/jSjNQACd




2017-06-29 6:25 GMT-03:00 Marco Pivetta <ocram...@gmail.com>:

> On Thu, Jun 29, 2017 at 11:19 AM, li...@rhsoft.net <li...@rhsoft.net>
> wrote:
>
> > in other languages like Visual Basic constants are fast, in PHP they are
> > slow, both in define and access
> >
>
> Two things here:
>
>  1. don't ever consider visual basic for any comparison of any sort: it's
> basically (ha!) the worst example of a programming language that I can
> think of before malborge
>  2. speed is not relevant in this scope: program correctness is. Final
> properties would allow switching value object representations from accessor
> (getter) based logic (extremely slow) to public property based (less
> overhead, also in writing).
>
> Marco Pivetta
>
> http://twitter.com/Ocramius
>
> http://ocramius.github.com/
>



-- 
David Rodrigues

Reply via email to