Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:122990 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 0D2281A009C for ; Sat, 6 Apr 2024 03:39:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1712374814; bh=GLfjYFpxgXx5gkmQ4+P9W2xxQXo70VJJVD1qxChbs5k=; h=From:Subject:Date:References:Cc:In-Reply-To:To:From; b=WWE1HckhokW1Zgxqaa/GE6Ee6DQbcLst5J5ilRglcwa7O/x7dDDKE+hXcue1FEn6i EJWDBaTseO1sQ8Y1bF/66N0GST0WfmXpIzJri1eqiVOS/71RjbcbM2sVL++IwNhwrE t1UagJQQZsR9fLaaqIlBeRKvv96t2qQ9WhRA8CsdymbkI4VO+pGcV+yKlTcdEps1q0 rEzRpxwM6hA7imSMXGuEt6Yrw8S3x8fnEi5QME8b+NLvSR6Xe6yzbzQRv44dzy+SIS 4Sn8sIlD79LRpyaJ5tElEs0On8xnxbqOu2xUoEnBUcvCpLFKL2tOVEM0Tu9s3EwlfC xyTG6W8/HiPOw== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 0D437180044 for ; Sat, 6 Apr 2024 03:40:11 +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=1.5 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,HTML_MESSAGE, MIME_HTML_ONLY,MIME_HTML_ONLY_MULTI,MIME_QP_LONG_LINE,MPART_ALT_DIFF, SPF_HELO_NONE,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 mail.sakiot.com (mail.sakiot.com [160.16.227.216]) (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 03:40:10 +0000 (UTC) Received: from smtpclient.apple (0.73.239.49.rev.vmobile.jp [49.239.73.0]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by mail.sakiot.com (Postfix) with ESMTPSA id 275AF401D9; Sat, 6 Apr 2024 12:39:37 +0900 (JST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=sakiot.com; s=default; t=1712374777; bh=GLfjYFpxgXx5gkmQ4+P9W2xxQXo70VJJVD1qxChbs5k=; h=From:Subject:Date:References:Cc:In-Reply-To:To:From; b=PmbXn9b93XWmdW2EPZUC6q/LypLgimNs3GA3Jm7Velcn4AbGhcl+Z/7vZge5LJkHf TRiWtQKcMh6knZp/PT/Gz9oX4PXA6MtSt2zRqLeNMOo98VeW6k99LJ+tUAYNOJsSZv gVWB3XrGdOCG+LkHXv3nd+5ukI+iH3UKljk7d4wI= Content-Type: multipart/alternative; boundary=Apple-Mail-FAAD4A38-C714-4153-80FB-48C99EEEF2A4 Content-Transfer-Encoding: 7bit Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net Mime-Version: 1.0 (1.0) Subject: Re: [PHP-DEV] [RFC] [Discussion] Support object type in BCMath Date: Sat, 6 Apr 2024 12:39:24 +0900 Message-ID: References: Cc: =?utf-8?Q?Tim_D=C3=BCsterhus?= , Lynn , Aleksander Machniak , php internals In-Reply-To: To: Jordan LeDoux X-Mailer: iPhone Mail (21D61) From: saki@sakiot.com (Saki Takamachi) --Apple-Mail-FAAD4A38-C714-4153-80FB-48C99EEEF2A4 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable
Hi T= im, Jordan,

On Fri, Apr 5, 2024 at 1:00=E2=80=AFPM Tim D=C3=BCsterhus &= lt;tim@bastelstu.be> wrote:
Hi

On 4/5/24 21:42, Saki Takamachi wrote:
> The only solution I can think of at the moment is to impose the constra= int that
> when computing operator overloading, if the operands are both objects, t= hey 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 =3D= random_int(1, 100);
         }
     }

     $a =3D new MyNumber(5);
     $a->doSomething();
     $b =3D new MyNumber(10);
     $b->doSomething();

     $what =3D $a + $b;

What should be the value of $what->importantMetadata be? The property is <= br> 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=C3=BCsterhus

That is an absurd exa= mple. Why would anyone use inheritance for that class design? If what you ar= e arguing is "if you look at use cases where composition is clearly the corr= ect choice then inheritance causes problems", then I'm not sure what the poi= nt of the discussion is.

Jordan

One of the points Tim makes that actually matter= s is how to get user-defined properties on child classes to be carried over t= o new instances when operators are used to calculate them. (It doesn't reall= y matter that the property is private.)

For example= , suppose you define a tax rate in a child class.

M= y country currently has a mix of 10% and 8% tax rates, so the tax rate prope= rty could contain either 8 or 10.

The question here= is, if add objects with different tax rates, what should the tax rate of th= e resulting object be? It may be that we shouldn't calculate objects with di= fferent tax rates in the first place, but we need to clarify the behavior wh= en we do actually do so.

I've come up with a few op= tions, but none of them are particularly smart. In fact, it's a very bad ide= a...

- If a child class has its own properties, the= ir values =E2=80=8B=E2=80=8Bmust match exactly before any calculations can b= e performed using operators.
- Properties defined in child classes= are always uninitialized when calculated by operators.
- Always a= pply the state of the left operand

Also, as I was t= hinking about this, I realized that $roundMode has the same problem. When ca= lculating with an operator, I needed to consider what should happen if two o= bjects have different $roundModes.

I'll try to thin= k of some more good ideas, but if you have any suggestions, please let me kn= ow.

Regards.

Saki
= --Apple-Mail-FAAD4A38-C714-4153-80FB-48C99EEEF2A4--