@Nikita Popov <nikita....@gmail.com> I'm not sure what you mean by saying
this:

> We're always explicit at the declaration site, it's const FOO, function
foo, class Foo etc


Regarding your message

>  Here mutability is decided by single $ character in the declaration,
which doesn't have a particular obvious connection to mutability.

Yes, that is not really obvious about property mutability when we look at
the code.
I think it is probably better to rephrase it into something like: New way
of properties definition without dollar sign. Not only do we remove dollar
sign, but these properties can not be reassigned.

Looking from this perspective we are trying to improve code quality and
developer experience. Using immutability (as well as type-hints with strict
typing)  makes code less error prone. This should be promoted in the PHP
community.
What I want to say is: good things should be easily done, easier than
things which are more error prone.

Again, about explicitness and obviousness.
Imagine (just for a second) that all existing properties are immutable by
default. Then someone submits RFC to add mutability for them. It is
accepted to add a new keyword like this:

```php
mutable public string $bar;
```

Hence I mean: currently we have one default option (mutable properties)
from 2 options. Why do we need to create such a long keyword just to use
readonly properties (if immutability is better than mutability)?

Regards, Eugene

On Fri, Jul 16, 2021 at 1:13 PM Bruce Weirdan <weir...@gmail.com> wrote:

> On Fri, Jul 16, 2021 at 9:45 AM Eugene Sidelnyk <zsidel...@gmail.com>
> wrote:
>
> > Readonly properties are really useful for DDD, where everything is going
> to
> > be immutable. It promotes best practices. However for people to use it,
> > syntax should be concise and brief.
>
> If every property of the class is readonly it would probably be better
> to declare that with a class modifier.
>
> E.g.
>
> ```php
> readonly class Entity {
>     public int $count;
>     public string $data;
> }
> ```
>
> Though `readonly` doesn't look like a perfect fit in that position to me.
>
> --
>   Best regards,
>       Bruce Weirdan                                     mailto:
> weir...@gmail.com
>

Reply via email to