Re: Readonly properties - immutability by default
| From: | Mike Schinkel | Date: | Sat, 17 Jul 2021 09:04:37 +0000 |
| Subject: | Re: Readonly properties - immutability by default | ||
| References: | 1 2 3 4 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-115450@lists.php.net to get a copy of this message | ||
> On Jul 17, 2021, at 1:40 AM, Eugene Sidelnyk <zsidelnik@gmail.com> wrote:
>
> > Having a "readonly" class where the properties are read-only by default makes
> > sense to me, but maybe the better way to do it is with an attribute?
>
> We already have such an attribute provided. It is called
> [
#[Immutable]](https://blog.jetbrains.com/phpstorm/2020/10/phpstorm-2020-3-eap-4/#immutable
> <https://blog.jetbrains.com/phpstorm/2020/10/phpstorm-2020-3-eap-4/#immutable>).
Actually, you are confusing PhpStorm's inclusion of PhpStorm-specific userland attributes where
the PhpStorm team are probably trying to drive defacto-standard meanings for those attributes they
documents with attributes that has specific meanings and behavior recognized by PHP itself.
Nothing against PhpStorm — it is my IDE/editor of choice and I applaud JetBrain's leadership
in this area — but their attributes are still just their attributes, not attributes defined by in
a PHP RFC.
> If the intention is to add some logic for attributes, then unlikely it is going to be accepted
> because attributes by definition are meta-data. It doesn't add any logic for program.
Actually, that is not true either. PHP already has one attribute that PHP itself recognizes, named
"Attribute." As Larry Garfield wrote[1]: "The #[Attribute] attribute tells PHP
“yes, this class can be loaded as an attribute.”
You can also see that future scope was explicitly envisioned[2] that some small number of attributes
might potentially be more than just metadata.
-Mike
[1] https://platform.sh/blog/2020/php-8-0-feature-focus-attributes/
<https://platform.sh/blog/2020/php-8-0-feature-focus-attributes/>
[2] https://wiki.php.net/rfc/attributes_v2#future_scope
<https://wiki.php.net/rfc/attributes_v2#future_scope>