On 8/3/25 11:30 AM, Rob Landers wrote:
I'm not sure that this is a bug. You can redeclare the same type and add hooks (or change them), which breaks all assumptions about substitutability.

No it doesn't, read the "Property type variance" section on the property hooks RFC:

Normal properties are neither covariant nor contravariant; their type may not 
change in a subclass. The reason for that is “get” operations MUST be 
covariant, and “set” operations MUST be contravariant. The only way for a 
property to satisfy both requirements is to be invariant.

With abstract properties (on an interface or abstract class) or virtual 
properties, it is possible to declare a property that has only a get or set 
operation. As a result, abstract properties or virtual properties that have 
only a get operation required MAY be covariant. Similarly, an abstract property 
or virtual property that has only a set operation required MAY be contravariant.

Once a property has both a get and set operation, however, it is no longer 
covariant or contravariant for further extension. That is, it is now invariant 
(as all properties are in 8.3 and earlier).

Your example code _does_ fail but this isn't because of the hooks (The getter from A->$v is inherited in C) it's because you've redeclared it without a default value and it's trying to access an uninitialized property: https://3v4l.org/pv39f#v8.4.11 vs https://3v4l.org/VD6ZK#v8.4.11

Reply via email to