Re: [PHP-DEV] Readonly properties - immutability by default

2021-07-17 Thread Eugene Sidelnyk
I don't think the way it is going to be realeased is elegant solution On Sat, Jul 17, 2021, 2:47 PM Andreas Leathley wrote: > On 16.07.21 09:06, Nikita Popov wrote: > > We cannot make properties readonly by default, because that would be a > > major backwards compatibility break. > > > > If

Re: [PHP-DEV] Readonly properties - immutability by default

2021-07-17 Thread Andreas Leathley
On 16.07.21 09:06, Nikita Popov wrote: We cannot make properties readonly by default, because that would be a major backwards compatibility break. If you're going for brevity, something you can do is omit the visibility specifier, as it is public by default. "readonly int $prop" works. Would

Re: [PHP-DEV] Readonly properties - immutability by default

2021-07-17 Thread Mike Schinkel
> On Jul 17, 2021, at 1:40 AM, Eugene Sidelnyk 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 >

Re: [PHP-DEV] Readonly properties - immutability by default

2021-07-17 Thread Eugene Sidelnyk
> Please don't top post. This is a bottom-post-centric list. Can you please tell me what mailing client you use and what should I? > if we were designing the language today we would do it very differently. This reminds me working with legacy code in the team which says to write the code in

Re: [PHP-DEV] Readonly properties - immutability by default

2021-07-16 Thread Eugene Sidelnyk
> 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]`](

Re: [PHP-DEV] Readonly properties - immutability by default

2021-07-16 Thread Mike Schinkel
> On Jul 16, 2021, at 6:12 AM, Bruce Weirdan wrote: > > On Fri, Jul 16, 2021 at 9:45 AM Eugene Sidelnyk 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

Re: [PHP-DEV] Readonly properties - immutability by default

2021-07-16 Thread Larry Garfield
On Fri, Jul 16, 2021, at 6:48 AM, Eugene Sidelnyk wrote: > @Nikita Popov 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 $

Re: [PHP-DEV] Readonly properties - immutability by default

2021-07-16 Thread Eugene Sidelnyk
@Nikita Popov 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

Re: [PHP-DEV] Readonly properties - immutability by default

2021-07-16 Thread Bruce Weirdan
On Fri, Jul 16, 2021 at 9:45 AM Eugene Sidelnyk 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

Re: [PHP-DEV] Readonly properties - immutability by default

2021-07-16 Thread Nikita Popov
On Fri, Jul 16, 2021 at 10:11 AM Eugene Sidelnyk wrote: > Thanks for your response! > Anyway, I probably put it wrong by saying "by default", so let me clarify > myself. > > What I really mean is omitting the dollar sign. So everything remains the > same with ordinary properties (which are

Re: [PHP-DEV] Readonly properties - immutability by default

2021-07-16 Thread AllenJB
On 16/07/2021 09:11, Eugene Sidelnyk wrote: Thanks for your response! Anyway, I probably put it wrong by saying "by default", so let me clarify myself. What I really mean is omitting the dollar sign. So everything remains the same with ordinary properties (which are mutable), and we introduce

Re: [PHP-DEV] Readonly properties - immutability by default

2021-07-16 Thread Pierre
Le 16/07/2021 à 10:11, Eugene Sidelnyk a écrit : Thanks for your response! Anyway, I probably put it wrong by saying "by default", so let me clarify myself. What I really mean is omitting the dollar sign. So everything remains the same with ordinary properties (which are mutable), and we

Re: [PHP-DEV] Readonly properties - immutability by default

2021-07-16 Thread Eugene Sidelnyk
Thanks for your response! Anyway, I probably put it wrong by saying "by default", so let me clarify myself. What I really mean is omitting the dollar sign. So everything remains the same with ordinary properties (which are mutable), and we introduce immutable (readonly) properties as another type

Re: [PHP-DEV] Readonly properties - immutability by default

2021-07-16 Thread Nikita Popov
On Fri, Jul 16, 2021 at 8:45 AM Eugene Sidelnyk wrote: > This is replica of github PR comments: > > Hi there! > Isn't it better to simplify this a bit? I mean `readonly` keyword is really > long to type every time we need such property. Earlier (in php7.3) > properties were defined only with

[PHP-DEV] Readonly properties - immutability by default

2021-07-16 Thread Eugene Sidelnyk
This is replica of github PR comments: Hi there! Isn't it better to simplify this a bit? I mean `readonly` keyword is really long to type every time we need such property. Earlier (in php7.3) properties were defined only with visibility modifier. Now it is going to become *t verbose*. ```php