3 ms·
> Does `$this->country =` use the setter even if it's in a hook (but not a `country` hook)? To me it is obvious hooks won't use other hooks because that could
by chx 2y ago
> Does `$this->country =` use the setter even if it's in a hook (but not a `country` hook)?
To me it is obvious hooks won't use other hooks because that could lead to an infinite loop in a hurry
> Does reading `$this->countryCode` use the getter hook, even it's from a `countryCode` hook?
same
> If not, is there a way to call the `countryCode` getter from this setter?
There is although it's a bit tricky and not intuitive but I feel this falls under the "it is enough this is possible, there's no need for it to be easy": "Be aware, the detection logic works on $this->[propertyName] directly at compile time, not on dynamic forms of it like $prop = 'beep'; $this->$prop. That will not trigger a backing value." Using dynamic properties in what should be simple code should be rare enough this is not a problem. It's like a bridge convention, the benefits vastly outweigh the drawbacks.
- c0wb0yc0d3r 2y ago> Does `$this->country =` use the setter even if it's in a hook (but not a `country` hook)? To me it is obvious hooks won't use other hooks because that could lead to an infinite loop in a hurry I would expect hooks for properties other than `$this->contryCode` to be called inside of a `$this->contryCode` hook. Btw the docs that are linked in the post[0] seem to be clearer than the example in the announcement. Reads less ambiguously to me. [0]: https://www.php.net/manual/en/migration84.new-features.php#migration84.new-features.core.property-hooks https://www.php.net/manual/en/migration84.new-features.php#m...
- alt227 2y agoYou are corect that the docs read much clearer. Why would they muddy the concept in the release post?
- patates 2y ago> To me it is obvious hooks won't use other hooks because that could lead to an infinite loop in a hurry Yet in Javascript: test = { set a(x) { this.b = x }, get a() { return 2 }, set b(x) { this.c = 10 }} Object { a: Getter & Setter, b: Setter } test.a = 10 10 test Object { a: Getter & Setter, b: Setter, c: 10 } and yes it's possible to make infinite loops.