Re: [RFC] [Discussion] Support object type in BCMath
| From: | Tim Düsterhus | Date: | Fri, 05 Apr 2024 20:00:32 +0000 |
| Subject: | Re: [RFC] [Discussion] Support object type in BCMath | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-122984@lists.php.net to get a copy of this message | ||
Hi
On 4/5/24 21:42, Saki Takamachi wrote:
The only solution I can think of at the moment is to impose the constraint that when computing operator overloading, if the operands are both objects, they must be of the exact same class.Even that would allow for confusing behavior:
class MyNumber extends Number {
private $importantMetadata;
public function doSomething() {
$this->importantMetadata = random_int(1, 100);
}
}
$a = new MyNumber(5);
$a->doSomething();
$b = new MyNumber(10);
$b->doSomething();
$what = $a + $b;What should be the value of $what->importantMetadata be? The property is private, so as a user adding two of MyNumber would not even be able to manually fix it up with the correct value, thus requiring the addition of a "fixup" method that fixes the internal state of the object, possibly even lacking the necessary information to properly fix up the state, because it does not know which operations lead to the state. Best regards Tim Düsterhus