On Sun, Jun 23, 2024, at 2:14 PM, Andreas Hennings wrote: > This leads me to a different question regarding property guards. > What if we validate an object property guard, which later changes? > > class C { > public function __construct( > public readonly Point $point is Point { $z: 0 }; > ) {} > } > > $c = new C(new Point(0, 0, 0)); > $c->point->z = 5; > > The second operation would violate the guard condition. > However, I suspect that the operation will not trigger any validation > for a guard where the object is referenced. > So it would be up to the developer to only use this if Point::$z is > readonly, or they cannot rely on the guard.
This is future-scope, so we won't delve into it too deeply. But the general idea (for me) is that a property guard pattern compiles down to a set hook on the property (or equivalent). That means it would apply to all writes to that property, unless you deliberately bypass it using reflection. So it would be no less (or more) of a guarantee than an equivalent set hook. --Larry Garfield