Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:122905 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 2F8D71A009C for ; Wed, 3 Apr 2024 00:43:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1712105014; bh=SQZOrNnR2318RrYYOYg+Th7qvYzwxjwPRcThUK9vdtU=; h=Subject:From:In-Reply-To:Date:Cc:References:To:From; b=IlYJWOgQH3ilxbrwLJ2lVeHcTa0+riSOMFUeek8l2guG4ZepjmrUMGwYEwodkiB2A 2PVuh0P+qTmtfMrS8nJDuzauYor65MgGLFvkACEI21Qpi9021PW1BxVusI4pKtgEJU 6e2VNDeSrVNtiiT7PGPBnA8w3CfQQA09d8rLZNCVG18tHOr0ifM4g/ZD/XKIBv6+p9 GL18fx5jmkFatdeonHOBVc+EDTe2U4tfck2l//nYXgmtkaoM8saxl1zBu9LMg4XmUz CP7Nt0+0SluD4QDom1hAPKB1TN5uRMwXEu8DDg3UrVnVEHCV//j4T6toyZCUq0bQ1/ No6QJMFisd0MA== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id BF73D180872 for ; Wed, 3 Apr 2024 00:43:33 +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,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 ; Wed, 3 Apr 2024 00:43:32 +0000 (UTC) Received: from smtpclient.apple (unknown [117.55.37.250]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.sakiot.com (Postfix) with ESMTPSA id 0746B401D9; Wed, 3 Apr 2024 09:43:03 +0900 (JST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=sakiot.com; s=default; t=1712104983; bh=SQZOrNnR2318RrYYOYg+Th7qvYzwxjwPRcThUK9vdtU=; h=Subject:From:In-Reply-To:Date:Cc:References:To:From; b=bsxTv45+g8yB7J2JhNYg7lAdLLNINkOdeMbuAUbb7cGUO2l51BcAWo9/KtRPxQXzf zH3PvrKXby6vWTzdSbDQaReX37GE1Un7qA0tnusNQ6k0vvxVXqRkPv4+Tx41eBwxzq cxW0CcM8D0jkpumR27Tdtl7f/QLeIq8iR/h9fHhg= Content-Type: text/plain; charset=us-ascii Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3731.700.6\)) Subject: Re: [PHP-DEV] [RFC] [Discussion] Support object type in BCMath In-Reply-To: Date: Wed, 3 Apr 2024 09:42:50 +0900 Cc: Lynn , Aleksander Machniak , php internals Content-Transfer-Encoding: quoted-printable Message-ID: <8FB87901-02D7-4934-9119-55B21CEDDA9D@sakiot.com> References: <4F094EDA-5058-407D-AF39-06FD934FDE1F@sakiot.com> <68CF373E-6ABF-4471-8992-813B4BA1B508@sakiot.com> <904197f4-afb5-401e-9e17-7a655c5449d0@alec.pl> <655FEA80-9AB4-4AAD-A310-70ED968C97A2@sakiot.com> To: Jordan LeDoux X-Mailer: Apple Mail (2.3731.700.6) From: saki@sakiot.com (Saki Takamachi) Hi Jordan, > The issue is that, presumably, this method will be used within the = operator overload portion of the class entry in C. If it is allowed to = be overridden, then this RFC is sort of providing a stealth operator = overload to PHP developers. As much as I am for operator overloads = having written an RFC for it, and as much as I find the arguments = generally against it lacking, I am not in favor of doing it that way = with a kind of... unspoken capability to overload the basic math = operators in userland. I very much like the feature, but I also think it = should be intentionally and specifically designed, which is why I spent = a long time on it. I do not get a vote for RFCs, but I would vote = against this if I could just for that reason IF the calculation methods = were not private, the class was not final, AND the function entry was = used in the operator overload. >=20 > And operator overloads are also the place where what you outlined = above gets murky. I think what you outlined is very close to a good = final design for just the method usage side, but the operator usage side = CANNOT provide a scale or a rounding mode. That should be taken into = consideration, because allowing this object to be used with operators is = probably the single largest benefit this RFC will provide to PHP = developers. >=20 > What I ended up doing was that the VALUE of the object was immutable, = but the other information was not immutable. That has its own downsides, = but does allow for very explicit control from the developer at the = section of code using the class, but also avoids creating copies of the = object or instantiating a new object for every single "setting" change = during calculations. Agree. I also have negative thoughts about this, but I wanted to hear = everyone's opinions, so I sent the email I mentioned earlier. If make a class final, users will not be able to add arbitrary methods, = so I think making each method final. Although it is possible to = completely separate behavior between method and opcode calculations, = this is inconsistent and confusing to users and should be avoided. > I should clarify, the portion of your outline that I feel is not = sufficient for the operator overload use case is that there is no way to = use both operator overloads AND a scale other than 10 + left operand = scale. How about setting the `$scale` and `$roundMode` that I mentioned earlier = in the constructor instead of `div` and `pow`? By doing so, we can use = any scale when calculating with opcodes. If we want to specify a = different scale for each calculation, you can do it using methods. Or would it be more convenient to have a method to reset `$scale` and = `$roundMode`? It is immutable, so when reset it returns a new instance. Regards. Saki=