> Le 9 juil. 2025 à 15:17, Nick <p...@nicksdot.dev> a écrit :
> 
> Hey Claude,
> 
> 
> I hear you, but I still struggle to fully grasp the issue. It’s genuinely 
> hard for me to come up with a real-world example that actually makes sense.
> Everything I’ve seen so far, including the RFC example and what I tried 
> myself (I gave it an honest shot), feels either very theoretical or entirely 
> intentional, and thus perfectly logical in its outcome.
> 
> In one of your previous mails you brought up an example that requires calling 
> a class method (read: intentionally changing class state), which  would 
> result in a non-consistent value being returned when calling the same 
> property more than once. I get it. But what if the user wants exactly that in 
> their `readonly` class?

Yes, it’s mostly theoretical, but it is good to base language design on sound 
theory.

But here is a potential practical issue. A random user wants to extend a class 
from a third-party library, but they are annoyed that a given property is 
readonly. Now, using a get hook, it is trivial for them to cheat and to work 
around what it perceives as an undue limitation, not realising that it may 
break assumptions made elsewhere in the library.  — Indeed, I don’t trust users 
and want to protect them against themselves.

> 
> That said I did address your concern here (actual RFC PR branch against 
> alternative; PoC):
> https://github.com/NickSdot/php-php-src/compare/allow-readonly-hooks...NickSdot:php-php-src:readonly-hooks-strict
> 
> Larry and I agree that we don’t want this complexity in the current RFC.
> Perhaps this is something for a separate `init` hook RFC?

I think indeed that it is not worth making the current proposal more complex, 
but rather considering whether implementing an init hook instead is a 
reasonable alternative.

Also there is another issue with the use of get hook for lazy initialisation 
(although not specific to readonly): The `??=` pattern breaks if the property 
is nullable and you initialise it to `null`. It is in fact cumbersome to 
distinguish between an uninitialised property and a property initialised with 
null.

—Claude

Reply via email to