Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:122998 X-Original-To: internals@lists.php.net Delivered-To: internals@lists.php.net Received: from php-smtp4.php.net (php-smtp4.php.net [45.112.84.5]) by qa.php.net (Postfix) with ESMTPS id 081E21A009C for ; Sat, 6 Apr 2024 13:43:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1712411063; bh=n8orAEzpPt3QOvp/bBj0R6buoLmbjTZmvPNasKPblwk=; h=Date:Subject:To:References:From:In-Reply-To:From; b=YComTVJKuRGXQYPPffXdK8QnkPDpacH+5mZAXXijlIXQ1g5d2nbHviDcZU1RWlcl4 ho7HpM892RxJZ+FDEppOUNx9MC4M0JnZvVOlLN8pG7j+wUal+0IdcmmrqWU3WV6EoP Y+laoihMJScd8pH8BNnlz4Fb9fdixBjySQdhu/6yEvJWmeRpWRQVLdTEifgJU9NSPB DQsV/mwjLUilcUSeFKcibOl+83uJjclVLdfOca+gsrIgfhtLYDafRhW7x+/Bc/Oyut HNxCDKvwbM5b+f/5KbGkvmorQSrX7hi7D1eRvJLAJlLUghynppvcR90PcqccbvWfQT BSeum1nAKAAzQ== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 45A6F180A34 for ; Sat, 6 Apr 2024 13:44:19 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-0.1 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_MISSING,HTML_MESSAGE, RCVD_IN_DNSWL_LOW,SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from wout1-smtp.messagingengine.com (wout1-smtp.messagingengine.com [64.147.123.24]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Sat, 6 Apr 2024 13:44:18 +0000 (UTC) Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.west.internal (Postfix) with ESMTP id 2083432000D9 for ; Sat, 6 Apr 2024 09:43:47 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Sat, 06 Apr 2024 09:43:47 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rwec.co.uk; h=cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm2; t=1712411026; x=1712497426; bh=/LYePwWexM 0W5xTFhjPs77BC/Nty6ToV+RuOjimrf6A=; b=G8W/pKG8BRfUfHbd8b75qeT3gR 8pzweJnT6elY8wxw+c4nVnYi8QpCEU3PCcjDBgtLOzrwWXNy0rdarwUgVzCcXW+x 59chzWNkU6qzvKF6gOhLq7IHbuaclMdewhGmWTEHMCaUT3Bjc2ZSqLO2sOEG7SP5 YtNxZMhiSlUmBInofUUu3Dl0PCX4lLzzzid5evplFUxWt3K4pb4RPAjC63NoEjNP 07fZ9CHqNdfQeidr1kpY+UB03/BYB/0yIETOxqgkjhudvD9Tbibf6/kqkj/8HV+z fsnxDdF/N/Qbb1qFEi9ELUi70i8cmvsvCq+B+tgqQo+5xnrGSYAgStk4c6Og== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm2; t=1712411026; x=1712497426; bh=/LYePwWexM0W5xTFhjPs77BC/Nty 6ToV+RuOjimrf6A=; b=ruZNe9fvQkqQtkBjO9L+W4n6kxhaVibuLdCzkvSlHKS5 bWGpUsJXZpNBGE4WCjmUAaNjSueEPnAuwkmxR00M0kofs6W0TWV9NOYlCt8xi0cR ZT4f5EdvSp2Oi8FPWT9rBLNdn71EP4BVMmG9IEPinjoHD8s7VsFAnMiy52QYBZHX RZcMzQpbzxvODlUEisWu9LFW7CAgfWnBqjGefG5meqXltrJek3BLyipxgl4OQTWx z32VtAKYJeX6Di8AcgCPHistQPekfT31XK0nXOllgPmRvpNxaPFJVHxoWHBaelhA zH1nQwSFWUUtPXj5a/n5vu0awyhFtpmrWnc5HXaSWQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrudegvddgjedtucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpegtkfffgggfuffvfhfhjgesrgdtre ertddvjeenucfhrhhomhepfdftohifrghnucfvohhmmhhinhhsucglkffoufhorfgnfdcu oehimhhsohhprdhphhhpsehrfigvtgdrtghordhukheqnecuggftrfgrthhtvghrnhephe etleeiiefgueduieeuieffvdevheduueefkeejuefgffeftdeitdegtedtleetnecuvehl uhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepihhmshhophdrph hhphesrhifvggtrdgtohdruhhk X-ME-Proxy: Feedback-ID: id5114917:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Sat, 6 Apr 2024 09:43:45 -0400 (EDT) Content-Type: multipart/alternative; boundary="------------VcJX031u40gGhR0xverXtevV" Message-ID: Date: Sat, 6 Apr 2024 14:43:43 +0100 Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PHP-DEV] [RFC] [Discussion] Support object type in BCMath To: internals@lists.php.net References: Content-Language: en-GB In-Reply-To: From: imsop.php@rwec.co.uk ("Rowan Tommins [IMSoP]") This is a multi-part message in MIME format. --------------VcJX031u40gGhR0xverXtevV Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit 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] --------------VcJX031u40gGhR0xverXtevV Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 7bit
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]
--------------VcJX031u40gGhR0xverXtevV--