Re: [RFC] Property write visibility
| From: | Marco Pivetta | Date: | Mon, 29 Jun 2020 15:44:16 +0000 |
| Subject: | Re: [RFC] Property write visibility | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-110782@lists.php.net to get a copy of this message | ||
Hey André,
This does indeed seem to cut into the traditional property accessors scope.
I'm no longer seeing a reason to have property accessors, since immutable
state (and promotion thereof) is much more relevant to fight bugs and
improve application performance and maintainability.
Therefore, I would endorse re-visiting the RFC at
https://wiki.php.net/rfc/write_once_properties
instead.
Máté also linked today (
https://twitter.com/kocsismate90/status/1277625002720968704)
that C# 9.0 is
getting init-only properties, which looks similar to the RFC linked above.
Assuming we solve annoyances around cloning, that would be a more sensible
way forward, while property accessors seem to perpetuate the bad practice
of getters and setters, which are the main cause for me having to fire up a
debugger in any environment.
Marco Pivetta
http://twitter.com/Ocramius
http://ocramius.github.com/
On Mon, Jun 29, 2020 at 11:42 AM André Rømcke <andre.romcke@gmail..com>
wrote:
> Good morning Internals,
>
> I'd like to start discussion on a new RFC proposing a way to be able to
> (optionally) specify property
> write visibility, separate from read:
>
> https://wiki.php.net/rfc/property_write_visibility
>
> This enables readonly, write-only and immutable like semantics for PHP's
> properties.
>
> These are the common use cases where users tend to resort to magic methods
> or setter/getter
> methods. This proposal will as such avoid unnecessary boilerplate, makes
> coding easier and more
> ergonomic, and in the case of magic method usage improve performance.
>
>
> Best,
> André Rømcke
>