Re: [PHP-DEV] Allow hooks in `readonly` promoted properties

2025-06-09 Thread Tim Düsterhus
Hi Am 2025-06-05 08:04, schrieb Nick: Semantically once you involved inheritance it isn't that easy. It is allowed to override an “unhooked” property with a hooked property and in the “Readonly Amendments” RFC we already decided that inheriting from a `readonly` class by a non-`readonly` class

Re: [PHP-DEV] Allow hooks in `readonly` promoted properties

2025-06-09 Thread Tim Düsterhus
Hi Am 2025-06-04 15:39, schrieb Nick: Your test cases really only scratch the surface of what should be tested. You are basically just verifying that it compiles. In fact you are not even testing that reassigning the property is disallowed, because the test fails due to a visibility error. In

Re: [PHP-DEV] Allow hooks in `readonly` promoted properties

2025-06-05 Thread Nick
Hey Larry, > On 6. Jun 2025, at 01:06, Larry Garfield wrote: >> Would this be expected to work? Can interface properties be declared >> `readonly`? >> interface Cleaned >> { >>public readonly string $clean { get; } // has readonly >> } > > Interface properties cannot be declared readonly to

Re: [PHP-DEV] Allow hooks in `readonly` promoted properties

2025-06-05 Thread Larry Garfield
On Thu, Jun 5, 2025, at 1:12 AM, Nick wrote: > Hey internals, > >> On 4. Jun 2025, at 20:19, Nick wrote: >>> I believe at the moment that RFC text is all there is. :-) I don't know >>> that it's worth opening a discussion without at least a mostly-done >>> implementation. Also, Ilija is rather

Re: [PHP-DEV] Allow hooks in `readonly` promoted properties

2025-06-04 Thread Nick
Hey internals, > On 4. Jun 2025, at 20:19, Nick wrote: >> I believe at the moment that RFC text is all there is. :-) I don't know >> that it's worth opening a discussion without at least a mostly-done >> implementation. Also, Ilija is rather busy on other tasks at the moment, as >> am I. (U

Re: [PHP-DEV] Allow hooks in `readonly` promoted properties

2025-06-04 Thread Nick
Hey Tim, > On 4. Jun 2025, at 21:09, Tim Düsterhus wrote: > > Semantically once you involved inheritance it isn't that easy. It is allowed > to override an “unhooked” property with a hooked property and in the > “Readonly Amendments” RFC we already decided that inheriting from a > `readonly`

Re: [PHP-DEV] Allow hooks in `readonly` promoted properties

2025-06-04 Thread Nick
Hey Tim, > On 4. Jun 2025, at 21:09, Tim Düsterhus wrote: > > Hi > > Am 2025-06-04 14:19, schrieb Nick: >> Fair. If someone really wants to add random_int(): "well, that assumption >> doesn't hold anymore, deal” from my side. > > Semantically once you involved inheritance it isn't that easy.

Re: [PHP-DEV] Allow hooks in `readonly` promoted properties

2025-06-04 Thread Tim Düsterhus
Hi Am 2025-06-04 14:19, schrieb Nick: Fair. If someone really wants to add random_int(): "well, that assumption doesn't hold anymore, deal” from my side. Semantically once you involved inheritance it isn't that easy. It is allowed to override an “unhooked” property with a hooked property and

Re: [PHP-DEV] Allow hooks in `readonly` promoted properties

2025-06-04 Thread Marc Bennewitz
Hi Larry, On 03.06.25 19:03, Larry Garfield wrote: On Mon, Jun 2, 2025, at 11:34 PM, Nick wrote: I would like to add, personally, I don’t believe the above is dumb: ```php class Dumb { public readonly int $value { get => $this->value * random_int(1, 100); } } ``` I think it is a legitimate u

Re: [PHP-DEV] Allow hooks in `readonly` promoted properties

2025-06-04 Thread Nick
Hey all, > On 4. Jun 2025, at 01:03, Larry Garfield wrote: > > It's about expectation setting. If you see a property marked `readonly`, > it's reasonable to expect this to be true: > > $foo->bar == $foo->bar; > > For a traditional field (pre-hooks), this would be trivially true. With > hoo

Re: [PHP-DEV] Allow hooks in `readonly` promoted properties

2025-06-03 Thread Larry Garfield
On Mon, Jun 2, 2025, at 11:34 PM, Nick wrote: > I would like to add, personally, I don’t believe the above is dumb: > > ```php > class Dumb { > public readonly int $value { get => $this->value * random_int(1, 100); } > } > ``` > > I think it is a legitimate use-case. > Why wouldn’t a `readonly` pr

Re: [PHP-DEV] Allow hooks in `readonly` promoted properties

2025-06-02 Thread Nick
Hey Larry, Thanks for your answer. > On 2. Jun 2025, at 21:39, Larry Garfield wrote: > This was discussed heavily in the design and discussion phase for hooks. The > main problem is that the expectations for readonly and the expectations for > hooks don't always align. For example, if a virt

Re: [PHP-DEV] Allow hooks in `readonly` promoted properties

2025-06-02 Thread Larry Garfield
On Mon, Jun 2, 2025, at 7:49 AM, Nick wrote: > Dear Internals, > > I am sending my first message here. Thank you all for your hard work! Greetings. > I believe promoted properties should allowed for `readonly` properties > and in `readonly` classes. This would help us to avoid the unnecessary >