Re: [RFC] [Discussion] Support object type in BCMath

From: Date: Sat, 06 Apr 2024 13:43:43 +0000
Subject: Re: [RFC] [Discussion] Support object type in BCMath
References: 1 2 3  Groups: php.internals 
Request: Send a blank email to internals+get-122998@lists.php.net to get a copy of this message
On 06/04/2024 07:24, Saki Takamachi wrote:
Take a look at the methods shown below:
protected static function resultPropertyRules(string $propertyName,
mixed $value1, mixed $value2): mixed {}
This method determines which operand value to use in the result after calculation for a property that the user has defined by extending the class.
While this is an intriguing idea, it only solves a narrow set of use cases. For instance: - The class might want different behaviour for different operations; e.g. Money(42, 'USD') + Money(42, 'USD') should give Money(84, 'USD'); but Money(42, 'USD') * Money(42, 'USD') should be an error. - Properties might need to interact with each other; e.g. Distance(2, 'metres') + Distance(2, 'feet') could result in Distance(2.6096, 'metres'); but if you calculate one property at a time, you'll end up with Distance(4, 'metres'), which is clearly wrong. The fundamental problem is that it ignores the OOP concept of encapsulation: how an object stores its internal state should not define its behaviour. Instead, the object should be able to directly define behaviour for the operations it supports. Regards, -- Rowan Tommins [IMSoP]

« previous php.internals (#122998) next »