Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:122985 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 328FC1ADA76 for ; Fri, 5 Apr 2024 20:01:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1712347341; bh=kiVuJIJWW7SsNi7CCoUzJnbBXD9gqugD8N3SbKEfVNA=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=g+GdcXymc2RVY4wdnO64uHz0b+lzVmtVB8q9fyQOeTh900BzNnroqQH7HdCXglzXe +xO15or7DeErQ2Zgi4iaCYSpyCnX6n4lHjofmOcTF4sYf8zyMoJTIgo2qERqTb74+X EkJzHP8XFAOooAGREJ5xLalfEtzSrH8x437hhCKSVMhgjH+QMR2sLjslRVnj/5EAnz 655xtZog9m9UxmhWmy7WUz0CKGhjsc/GmGpOxln0VcjjqZz5ehLBHfPvjXgo3MjSTC 7X5CsY5QCQdum0Z/RAf2VKgeH2RZelRxz7D/1uLZB2KS6YANTxRZig+DZG/odpWqKU AlKLlwO4MYSDA== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 45F69180A40 for ; Fri, 5 Apr 2024 20:02: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.6 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,FREEMAIL_FROM, HTML_MESSAGE,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL, 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-pj1-f42.google.com (mail-pj1-f42.google.com [209.85.216.42]) (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 ; Fri, 5 Apr 2024 20:02:16 +0000 (UTC) Received: by mail-pj1-f42.google.com with SMTP id 98e67ed59e1d1-2a2f007a33dso1508748a91.0 for ; Fri, 05 Apr 2024 13:01:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1712347305; x=1712952105; darn=lists.php.net; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=kiVuJIJWW7SsNi7CCoUzJnbBXD9gqugD8N3SbKEfVNA=; b=Q1eSA1lWDHOGOXPgTJ1SRJmz/FN4IcpXhctMEiKnyiS+BOPfRbaMcysH5FVTKFsj7E Vouv+UfpapXHQiqz5EO3WZTQSwVmy2PNkKmn66eDmRt0KliKkBrX9jRASB7hh9f76B53 VrLoFrpOO0/YVgiEf30oJ50Fw0Exwpb+542kXCZrKo9hKIe81d1RofVQrUB9zq+a07FM fUSOsuIxLI/FLh5hyGIRu3k+WylubdT9MrH/LqiIMRnuC0hvwm0Fc2zyke9edmiWZD67 VOFunFVvXsHBJwGhPhIjJ0KM+xHMlDcHzTmfz26Q7Cbwk35wr7DtR307oMk9zqoY2NBb m7jQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712347305; x=1712952105; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=kiVuJIJWW7SsNi7CCoUzJnbBXD9gqugD8N3SbKEfVNA=; b=HndFVTVCvxAhcenhxFnQSw0KcnbeciPt2scVC/dClqLEYS+0y36wIuj+8fy7h6NnUR aSr5QegRtowxvBeqfwps9gzfvdl8nSNq8fIbL2l3hlkYiNKhG3CpDPgQ7prF92zTIPJJ BRqsJXAIs5S03SmL4KUx/OQjzPrWO1mLtd9UB29PJAzcryM+2R/HTIrMzr4OhuhI8n1h 7/Q+1LHlK4dn/z2nTHiZCJACXmeIiye4emzcfVEWPJXjg2KcupvMUAWtDBylK7dBfa/W 42/1vAxVSS0RN4raTabL0a2WO93rKUQsMiOTvRP4NuFtI/EP5W70AqKzwvBuYnpWg+sn 7tgA== X-Forwarded-Encrypted: i=1; AJvYcCXsQzBKswvuKTfZKcFeYy4HthQw9LIrI0V6x9drNtspGWRQgS+98W6C4Sr+yVsGYeSYA9depXDME1/AMkZNXiMDoKY+SKEwiw== X-Gm-Message-State: AOJu0YweEp7ZroMtgIkZzX2rlyNzyHXB2iAf94pWCaNr48HF+jZmYGb6 YczjmSAqNCxj4oFAZXZ2eMMQg3vLzIxY98vE7iRPidf9Az1BYCWX2JIpbbWGeIHjFr5BgsyfBxw H++rRjlu7O5kdDaTz7rDTLxin0LY= X-Google-Smtp-Source: AGHT+IEEsUb0y3bGE0E32JhqYs9tH0jVkdVv13uDYPE/m5UGXSIBO/isePrWUdkCHxnAC6iV4WW6JGBjZa115GNyHtA= X-Received: by 2002:a17:90a:3d44:b0:2a2:acf3:4108 with SMTP id o4-20020a17090a3d4400b002a2acf34108mr2946720pjf.0.1712347305595; Fri, 05 Apr 2024 13:01:45 -0700 (PDT) Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net MIME-Version: 1.0 References: <46B14427-44B2-4665-BC14-6018AC34B0CF@sakiot.com> In-Reply-To: <46B14427-44B2-4665-BC14-6018AC34B0CF@sakiot.com> Date: Fri, 5 Apr 2024 13:01:28 -0700 Message-ID: Subject: Re: [PHP-DEV] [RFC] [Discussion] Support object type in BCMath To: Saki Takamachi Cc: =?UTF-8?Q?Tim_D=C3=BCsterhus?= , Lynn , Aleksander Machniak , php internals Content-Type: multipart/alternative; boundary="000000000000e1e23f06155eec3a" From: jordan.ledoux@gmail.com (Jordan LeDoux) --000000000000e1e23f06155eec3a Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Fri, Apr 5, 2024 at 12:42=E2=80=AFPM Saki Takamachi wr= ote: > > The only solution I can think of at the moment is to impose the constrain= t > that when computing operator overloading, if the operands are both object= s, > they must be of the exact same class. > > When calculating using a method, it is clear which object should be > prioritized, so there is no risk of breaking down even if the method > accepts objects of different classes as arguments. It would be possible t= o > unify the behavior of the methods with operator overloading, but this wou= ld > be undesirable because the arguments would be contravariant. > > This is something that there are established solutions for actually. It's called Polymorphic Handler Resolution. This essentially means that when you have two objects used with operators, if they share a parent class or a class structure, the newest descendant is given priority. For example, if you have class A as the parent, then class B and class C as children: A + B =3D B, because it is a child class of A B + A =3D B, because it is a child class of A B + C =3D B, because neither are direct descendants C + B =3D C, because neither are direct descendants If we add the requirement that they must either be the same class as you suggested, OR one must be a descendant of the other, then we eliminate the B + C issue entirely, which makes sense for a BCMath object. How this would actually be implemented in C is that both operands would be checked for inheritance. If they are different classes and one is not the descendant of the other, it would error. If they are different classes and one IS the descendant of the other, then the handler for the descendant would be called, and that handler would always return an instance of itself. Jordan --000000000000e1e23f06155eec3a Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable





--000000000000e1e23f06155eec3a--