Re: Property Hooks Discussion
| From: | Zoltán Fekete | Date: | Tue, 11 Apr 2023 15:37:08 +0000 |
| Subject: | Re: Property Hooks Discussion | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-119933@lists.php.net to get a copy of this message | ||
> Ah, I see now what you meant, Robert. This already doesn't hold.
>
> class Foo {
> public int $prop;
> }
> $foo = new Foo();
> $value = '42';
> $foo->prop = $value;
> var_dump($value === $foo->prop);
> // false
I don’t know if this has been closed or discussed further in private but this has just came to me:
This could be solved with some kind of an operator overloading for the property, but then it would
just raise more questions to answer / problems to solve. But the problem mentioned above can well
happen even if one would use the same types.
class Baz {
public function clone(): self {
// create new instance into which I copy all my properties.
}
}
class Foo {
public Baz $val {
beforeSet(Baz $new) => $new->clone();
}
}