Re: [PHP-DEV] [RFC] [DISCUSSION] Immutable/final/readonly properties

2020-03-16 Thread Larry Garfield
On Mon, Mar 16, 2020, at 11:25 AM, Nicolas Grekas wrote: > > > I repeat what I wrote before but all those problems would disappear if we > > > were to bind the proposal to visibility: > > > https://externals.io/message/108675#108753 > > > > > > We could even consider splitting "read" and "write"

Re: [PHP-DEV] [RFC] [DISCUSSION] Immutable/final/readonly properties

2020-03-16 Thread Nicolas Grekas
> > I repeat what I wrote before but all those problems would disappear if we > > were to bind the proposal to visibility: > > https://externals.io/message/108675#108753 > > > > We could even consider splitting "read" and "write" in two separate > > keywords, each bound to visibility, isn't it? >

Re: [PHP-DEV] [RFC] [DISCUSSION] Immutable/final/readonly properties

2020-03-16 Thread Larry Garfield
On Mon, Mar 16, 2020, at 6:57 AM, Nicolas Grekas wrote: > Le lun. 16 mars 2020 à 12:52, Máté Kocsis a écrit : > > > > > > > The other one is the recently declined > > > https://wiki.php.net/rfc/object-initializer. As it basically works by > > > first > > > creating the object normally (including

Re: [PHP-DEV] [RFC] [DISCUSSION] Immutable/final/readonly properties

2020-03-16 Thread Nicolas Grekas
Le lun. 16 mars 2020 à 12:52, Máté Kocsis a écrit : > > > > The other one is the recently declined > > https://wiki.php.net/rfc/object-initializer. As it basically works by > > first > > creating the object normally (including a possible constructor call), and > > then assigning the specified

Re: [PHP-DEV] [RFC] [DISCUSSION] Immutable/final/readonly properties

2020-03-16 Thread Máté Kocsis
> > The other one is the recently declined > https://wiki.php.net/rfc/object-initializer. As it basically works by > first > creating the object normally (including a possible constructor call), and > then assigning the specified properties, this would not be compatible with > readonly properties

Re: [PHP-DEV] [RFC] [DISCUSSION] Immutable/final/readonly properties

2020-03-16 Thread Jakob Givoni
On Mon, Mar 16, 2020 at 4:47 AM Rowan Tommins wrote: > I'm sure different people will react differently, but my intuition is quite > the opposite: I would probably call the inline assignment to the property > an "initial value", not a "default value", and I would intuitively compare > it to

Re: [PHP-DEV] [RFC] [DISCUSSION] Immutable/final/readonly properties

2020-03-16 Thread Nikita Popov
On Mon, Mar 16, 2020 at 12:23 AM Larry Garfield wrote: > On Sun, Mar 15, 2020, at 4:44 PM, Máté Kocsis wrote: > > > > > > Avoiding that confusion will save the industry millions of dollars. > > > > > > > On the one hand, you are right, because currently it's not very useful to > > effectively

Re: [PHP-DEV] [RFC] [DISCUSSION] Immutable/final/readonly properties

2020-03-16 Thread Rowan Tommins
On Sun, 15 Mar 2020 at 21:41, Jakob Givoni wrote: > On Sun, Mar 15, 2020, at 8:48 AM, Marco Pivetta wrote: > > I think what will happen is that people will start requesting for > read-only > > properties with default values to be over-writable-once > > Exactly, I think that intuitively,

Re: [PHP-DEV] [RFC] [DISCUSSION] Immutable/final/readonly properties

2020-03-15 Thread Larry Garfield
On Sun, Mar 15, 2020, at 4:44 PM, Máté Kocsis wrote: > > > > Avoiding that confusion will save the industry millions of dollars. > > > > On the one hand, you are right, because currently it's not very useful to > effectively provide two > ways of declaring a constant. On the other hand however,

Re: [PHP-DEV] [RFC] [DISCUSSION] Immutable/final/readonly properties

2020-03-15 Thread Máté Kocsis
> > Avoiding that confusion will save the industry millions of dollars. > On the one hand, you are right, because currently it's not very useful to effectively provide two ways of declaring a constant. On the other hand however, if we also consider a longer term aim of adding support for object

Re: [PHP-DEV] [RFC] [DISCUSSION] Immutable/final/readonly properties

2020-03-15 Thread Jakob Givoni
On Sun, Mar 15, 2020, at 8:48 AM, Marco Pivetta wrote: > I think what will happen is that people will start requesting for read-only > properties with default values to be over-writable-once Exactly, I think that intuitively, developers will not see a default value as an actual "write". They will

Re: [PHP-DEV] [RFC] [DISCUSSION] Immutable/final/readonly properties

2020-03-15 Thread Larry Garfield
On Sun, Mar 15, 2020, at 8:48 AM, Marco Pivetta wrote: > Hey Máté, > > On Sun, Mar 15, 2020, 14:04 Máté Kocsis wrote: > > > Hi Marco, > > > > Yes, it still allows default values. > > > > The reason why I'm reluctant to disallow them is that this restriction > > would feel a bit ad-hoc for me. I

Re: [PHP-DEV] [RFC] [DISCUSSION] Immutable/final/readonly properties

2020-03-15 Thread Marco Pivetta
Hey Máté, On Sun, Mar 15, 2020, 14:04 Máté Kocsis wrote: > Hi Marco, > > Yes, it still allows default values. > > The reason why I'm reluctant to disallow them is that this restriction > would feel a bit ad-hoc for me. I mean, I wouldn't like to add another > special rule for "write-once"

Re: [PHP-DEV] [RFC] [DISCUSSION] Immutable/final/readonly properties

2020-03-15 Thread Máté Kocsis
Hi Marco, Yes, it still allows default values. The reason why I'm reluctant to disallow them is that this restriction would feel a bit ad-hoc for me. I mean, I wouldn't like to add another special rule for "write-once" properties, unless there is a strong argument for it. Besides, as far as I

Re: [PHP-DEV] [RFC] [DISCUSSION] Immutable/final/readonly properties

2020-03-14 Thread Marco Pivetta
Hey Máté, Is the RFC still gonna allow default values (constants, at this point)? While I don't see a major problem with it, it seems a bit weird... On Sat, Mar 14, 2020, 12:00 Máté Kocsis wrote: > Thank you, Larry, for your response! I share your opinion. However, I'd be > curious if there

Re: [PHP-DEV] [RFC] [DISCUSSION] Immutable/final/readonly properties

2020-03-14 Thread Máté Kocsis
Thank you, Larry, for your response! I share your opinion. However, I'd be curious if there is anyone who doesn't? As things currently stand, I plan to start the vote on Monday with an unchanged proposal (+ an extended future scope section). Máté

Re: [PHP-DEV] [RFC] [DISCUSSION] Immutable/final/readonly properties

2020-03-12 Thread Larry Garfield
On Thu, Mar 12, 2020, at 8:57 AM, Máté Kocsis wrote: > As you might noticed, I've not opened the vote yet. Partly because I was > improving > my implementation as well as the RFC itself (added some words about the > inheritance > implications), but the main reason is that a question arise in the >

Re: [PHP-DEV] [RFC] [DISCUSSION] Immutable/final/readonly properties

2020-03-12 Thread Máté Kocsis
As you might noticed, I've not opened the vote yet. Partly because I was improving my implementation as well as the RFC itself (added some words about the inheritance implications), but the main reason is that a question arise in the meanwhile. Namely, "write-once" properties could in principle

Re: [PHP-DEV] [RFC] [DISCUSSION] Immutable/final/readonly properties

2020-03-07 Thread Máté Kocsis
TL;DR; I plan to open the vote on Monday because the proposal feels complete for me. Read more to find out why I think so. Nicolas, do you have any specific use-case in mind that would require a workaround outlined in my previous email above the current possibilities (lazy initialization,

Re: [PHP-DEV] [RFC] [DISCUSSION] Immutable/final/readonly properties

2020-03-05 Thread Máté Kocsis
> > I totally agree with this: there must be a way to work around the keyword - > either via reflection or another means. Via Reflection, it could be a new method `->setWritable(true)` (next to > `->setAccessible(true)`). > I'm OK to support working around the keyword via reflection. Since my

Re: [PHP-DEV] [RFC] [DISCUSSION] Immutable/final/readonly properties

2020-02-25 Thread Nicolas Grekas
Le lun. 24 févr. 2020 à 21:35, Larry Garfield a écrit : > On Mon, Feb 24, 2020, at 7:55 AM, Rowan Tommins wrote: > > On Fri, 21 Feb 2020 at 23:18, Larry Garfield > wrote: > > > > > The with*() method style requires cloning the object. What happens to > the > > > locked status of a set property

Re: [PHP-DEV] [RFC] [DISCUSSION] Immutable/final/readonly properties

2020-02-25 Thread Máté Kocsis
Sorry, but I'd like to add a correction to my previous email. After thinking about it, I realized that cloning is not that serious of a problem in case of immutable objects, since it's also possible to create a new instance instead of cloning. So it seems to be only a Developer Experience concern

Re: [PHP-DEV] [RFC] [DISCUSSION] Immutable/final/readonly properties

2020-02-25 Thread Máté Kocsis
My original idea was to discuss cloning in connection with immutable objects, - I think it's only a serious problem in that case - but we can bring this discussion earlier of course, as readonly properties certainly has some effect on the clonability of objects. When I started working on

Re: [PHP-DEV] [RFC] [DISCUSSION] Immutable/final/readonly properties

2020-02-24 Thread Larry Garfield
On Mon, Feb 24, 2020, at 3:25 PM, Mike Schinkel wrote: > > On Feb 23, 2020, at 12:06 PM, Larry Garfield wrote: > > > > On Sun, Feb 23, 2020, at 2:39 AM, Mike Schinkel wrote: > >>> On Feb 21, 2020, at 6:17 PM, Larry Garfield > >>> wrote: > >>> I'm totally on board for better value object

Re: [PHP-DEV] [RFC] [DISCUSSION] Immutable/final/readonly properties

2020-02-24 Thread Terje Slettebø
Mike Schinkel wrote: On Feb 21, 2020, at 6:17 PM, Larry Garfield wrote: Separate visibility for internal and external access is a separate matter. (Also potentially useful, but not part of the write-once proposal at the moment.) This just hit me, so I think I will mention it. The

Re: [PHP-DEV] [RFC] [DISCUSSION] Immutable/final/readonly properties

2020-02-24 Thread Mike Schinkel
> On Feb 24, 2020, at 8:55 AM, Rowan Tommins wrote: > > As with typed properties, I wonder if there's a way we can introduce Now you are talking! This gives me hope after my dejected last comment on the list. -Mike -- PHP Internals - PHP Runtime Development Mailing List To

Re: [PHP-DEV] [RFC] [DISCUSSION] Immutable/final/readonly properties

2020-02-24 Thread Mike Schinkel
> On Feb 23, 2020, at 12:06 PM, Larry Garfield wrote: > > On Sun, Feb 23, 2020, at 2:39 AM, Mike Schinkel wrote: >>> On Feb 21, 2020, at 6:17 PM, Larry Garfield wrote: >>> I'm totally on board for better value object support, so that's a good >>> motive for me. The question I have is whether

Re: [PHP-DEV] [RFC] [DISCUSSION] Immutable/final/readonly properties

2020-02-24 Thread Larry Garfield
On Mon, Feb 24, 2020, at 7:55 AM, Rowan Tommins wrote: > On Fri, 21 Feb 2020 at 23:18, Larry Garfield wrote: > > > The with*() method style requires cloning the object. What happens to the > > locked status of a set property if the object is cloned? Are they then > > settable again, or do they

Re: [PHP-DEV] [RFC] [DISCUSSION] Immutable/final/readonly properties

2020-02-24 Thread Rowan Tommins
On Fri, 21 Feb 2020 at 23:18, Larry Garfield wrote: > The with*() method style requires cloning the object. What happens to the > locked status of a set property if the object is cloned? Are they then > settable again, or do they come pre-locked? > > Neither of those seem good, now that I

Re: [PHP-DEV] [RFC] [DISCUSSION] Immutable/final/readonly properties

2020-02-24 Thread Marco Pivetta
On Mon, Feb 24, 2020, 09:19 Rowan Tommins wrote: > On 24 February 2020 03:26:19 GMT+00:00, Marco Pivetta > wrote: > >The solution is trivial: don't use cloning: > > > >final class Foo > >{ > >public function withBar($bar):self { > >$instance = new self(); > >$instance->foo =

Re: [PHP-DEV] [RFC] [DISCUSSION] Immutable/final/readonly properties

2020-02-24 Thread Rowan Tommins
On 24 February 2020 03:26:19 GMT+00:00, Marco Pivetta wrote: >The solution is trivial: don't use cloning: > >final class Foo >{ >public function withBar($bar):self { >$instance = new self(); >$instance->foo = $foo; >// more assignments here - unavoidable >

Re: [PHP-DEV] [RFC] [DISCUSSION] Immutable/final/readonly properties

2020-02-23 Thread Marco Pivetta
Hey Larry, On Sun, Feb 23, 2020, 18:06 Larry Garfield wrote: > > It does not. > > 1) Race condition if I assume that a public write-once property is a > materialized value, but access it before it gets materialized. > This is alrey true for any public typed properties without default values,

Re: [PHP-DEV] [RFC] [DISCUSSION] Immutable/final/readonly properties

2020-02-23 Thread Larry Garfield
On Sun, Feb 23, 2020, at 2:39 AM, Mike Schinkel wrote: > > On Feb 21, 2020, at 6:17 PM, Larry Garfield wrote: > > I'm totally on board for better value object support, so that's a good > > motive for me. The question I have is whether this is really a good > > stepping stone in that direction

Re: [PHP-DEV] [RFC] [DISCUSSION] Immutable/final/readonly properties

2020-02-23 Thread Mike Schinkel
> On Feb 21, 2020, at 6:17 PM, Larry Garfield wrote: > I'm totally on board for better value object support, so that's a good motive > for me. The question I have is whether this is really a good stepping stone > in that direction or if it would lead down a wrong path and lock us into too >

Re: [PHP-DEV] [RFC] [DISCUSSION] Immutable/final/readonly properties

2020-02-21 Thread Andreas Hennings
When writing immutable classes, I want to be able to set properties in static factories and in wither methods. Once the new instance is sent to the outside world, its properties can be locked to prevent further modification. This sounds to me like we need different modes. Either the object

Re: [PHP-DEV] [RFC] [DISCUSSION] Immutable/final/readonly properties

2020-02-21 Thread Larry Garfield
On Fri, Feb 21, 2020, at 4:29 AM, Máté Kocsis wrote: > > > > Yeah, I'm definitely thinking in relation to the earlier discussion, since > > I think they're all inter-related. (This, property accessors, and constant > > expressions.) > > > > The biggest question is whether it's worth to support

Re: [PHP-DEV] [RFC] [DISCUSSION] Immutable/final/readonly properties

2020-02-21 Thread Máté Kocsis
> > Of course, that does leave the question of how often you need one or the > other. Maybe just the asymmetric visibility is sufficient for most > practical purposes, in which case it may not be worthwhile to introduce > readonly properties as a separate feature. > The examples shown in my

Re: [PHP-DEV] [RFC] [DISCUSSION] Immutable/final/readonly properties

2020-02-21 Thread Máté Kocsis
> > Yeah, I'm definitely thinking in relation to the earlier discussion, since > I think they're all inter-related. (This, property accessors, and constant > expressions.) > The biggest question is whether it's worth to support both readonly properties and property accessors. My answer is clear

Re: [PHP-DEV] [RFC] [DISCUSSION] Immutable/final/readonly properties

2020-02-20 Thread Larry Garfield
On Thu, Feb 20, 2020, at 3:06 AM, Nikita Popov wrote: > On Thu, Feb 20, 2020 at 1:27 AM Matthew Brown > wrote: > > > Someone recently requested something similar for a PHP static analysis tool > > I wrote (https://psalm.dev/r/f75997a263), though that version only allows > > lazy initialisation

Re: [PHP-DEV] [RFC] [DISCUSSION] Immutable/final/readonly properties

2020-02-20 Thread Nikita Popov
On Thu, Feb 20, 2020 at 1:27 AM Matthew Brown wrote: > Someone recently requested something similar for a PHP static analysis tool > I wrote (https://psalm.dev/r/f75997a263), though that version only allows > lazy initialisation inside the class in which a given property is declared. > >

Re: [PHP-DEV] [RFC] [DISCUSSION] Immutable/final/readonly properties

2020-02-20 Thread Máté Kocsis
> > I would expect that operating on one of these properties before it's > initialized will throw an error: > Actually, the RFC only says that the "immutability" of properties is guaranteed after initialization. We could of course change this premise, but that would make some important use-cases

Re: [PHP-DEV] [RFC] [DISCUSSION] Immutable/final/readonly properties

2020-02-19 Thread Matthew Brown
Someone recently requested something similar for a PHP static analysis tool I wrote (https://psalm.dev/r/f75997a263), though that version only allows lazy initialisation inside the class in which a given property is declared. Personally I don't like either approach – I think per-property getters

Re: [PHP-DEV] [RFC] [DISCUSSION] Immutable/final/readonly properties

2020-02-19 Thread Larry Garfield
On Wed, Feb 19, 2020, at 1:36 PM, Marco Pivetta wrote: > On Wed, Feb 19, 2020, 19:51 Larry Garfield wrote: > > > On Wed, Feb 19, 2020, at 11:05 AM, Máté Kocsis wrote: > > > Hi Internals, > > > > > > I'd like to move my RFC forward to the discussion phase: > > >

Re: [PHP-DEV] [RFC] [DISCUSSION] Immutable/final/readonly properties

2020-02-19 Thread Marco Pivetta
On Wed, Feb 19, 2020, 19:51 Larry Garfield wrote: > On Wed, Feb 19, 2020, at 11:05 AM, Máté Kocsis wrote: > > Hi Internals, > > > > I'd like to move my RFC forward to the discussion phase: > > https://wiki.php.net/rfc/write_once_properties > > > > In short, I propose to add support for a new

Re: [PHP-DEV] [RFC] [DISCUSSION] Immutable/final/readonly properties

2020-02-19 Thread Larry Garfield
On Wed, Feb 19, 2020, at 11:05 AM, Máté Kocsis wrote: > Hi Internals, > > I'd like to move my RFC forward to the discussion phase: > https://wiki.php.net/rfc/write_once_properties > > In short, I propose to add support for a new property modifier that would > allow properties to be initialized,

Re: [PHP-DEV] [RFC] [DISCUSSION] Immutable/final/readonly properties

2020-02-19 Thread Marco Pivetta
Hey Mark, Asking here as well, so that others are aware: is `unset($this->aPropertyThatWasNotInitializedBefore)` still working with this patch? Also, are the semantics around `__get`, `__set` and `__isset` the same as with typed properties? In the RFC, you have `unset($foo->c)` as disallowed:

[PHP-DEV] [RFC] [DISCUSSION] Immutable/final/readonly properties

2020-02-19 Thread Máté Kocsis
Hi Internals, I'd like to move my RFC forward to the discussion phase: https://wiki.php.net/rfc/write_once_properties In short, I propose to add support for a new property modifier that would allow properties to be initialized, but not modified afterwards. Cheers, Máté Kocsis