Hi

On 7/18/25 17:49, Rob Landers wrote:
Wasn’t that the entire point of readonly classes? Because it was painful to 
write readonly for every property.

It was certainly *one point*, but not the *entire* point. Quoting from the RFC (https://wiki.php.net/rfc/readonly_classes):

"it's still not easy to declare (quasi-)immutable classes"

and then further:

"it will prevent the creation of dynamic properties"

and

"a readonly class can only extend a readonly parent"

So the point of the RFC is not "adding readonly for every property is verbose", but "I want to be able to define immutable classes", which, as I outlined before, is something different.

The behavior of the class doesn’t magically change. Or, at least, I hope it 
doesn’t.

The behavior of the class changes, since dynamic properties will now be legal. It also breaks any child classes, since child classes of non-readonly classes may not be readonly (not even if all properties are already readonly). The behavior doesn't change magically, though, it changes due to the intentional removal of the `readonly` keyword on the class.

Unless I missed something. Hooks are fancy methods? There is nothing intrinsic 
about object properties. There is nothing that says two calls to the same 
property’s getters are going to result in the same values. There is 
asynchronous php, declare ticks, etc. especially in the case of globals, there 
is no guarantee you even have the same object. At the end of the day, it is up 
to the programmer building that system / program to provide those guarantees— 
not the language.

I agree with both Eric's response to this paragraph.

Best regards
Tim Düsterhus

Reply via email to