Le 03/02/2021 à 15:14, Nikita Popov a écrit :
I've written up an initial draft for property accessors at
https://wiki.php.net/rfc/property_accessors, but once again I get the
distinct impression that this is adding a lot of language complexity, that
is possibly not justified (and it will be more complex once inheritance is
fully considered).
Overall, I'm still completely unsure what we should be doing :)
Regards,
Nikita
Hello,
I love pretty much everything of this draft, it will allow to write
value types in a very concise manner.
Various notes thought:
* Visibility modifier (public, protected, private) is useless and
could be dropped entirely (I don't like var, but if that's necessary
to keep it OK) for properties with asymmetric visibility directives,
I don't know if the current parser will let you do that easily, but
that would be a huge win for developers (even more concise code).
* I love the fact that it can be combined with constructor promotion.
* I love the guard and lazy features as proposed.
Regarding inheritance, obviously the most important point is that
interface or class contracts should not be changed, so you may open for
reading a closed property, but you may not close a readable property for
example. This is true for writing as well of course. You're saying
basically that a get'ed property would be passed by-value and thus it
would forbid indirect access such as adding values to an array ? But
what if the compiler could detect that get; is just get and not a
function behind and compile opcodes as if it was a normal property (I
don't know Zend internals at all, just guessing here) and considers that
any other more complex getter to just be incompatible ? I guess that in
languages such as C# that implement such asymmetric visibility
mechanism, they always return object references, so this kind of problem
just doesn't exist.
Thank you so much for this draft, I love the path it follows.
Regards,
--
Pierre