Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:122963 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 5E1711A009C for ; Fri, 5 Apr 2024 10:57:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1712314706; bh=kSDkILpcXBjlzN6/Gg/JD1cZ09noKEho3sAJfysQEF8=; h=Date:Subject:To:References:From:In-Reply-To:From; b=gs3VFyZtmaMI+h3zjUUgRBZ7Q3906W1EBP7NwMJ6su64N9LjfpgVJv22IW5F/VgQ1 hLL7Z+H8JvkP0gHRdYScqTTsbJOd688N0QVPZGdlzPsC6ke+01z/5nphS5gmnMQIMt UJbjAYsK1gbuFxm6yVBQ80sPK2M7bsiJcoXuo8+pllOkJg1gA5B81IsJ5lL88wtmyA aibg4n/HJDLvuZjVINZP2p5EV5Hu14Q5HzxJVFqS4LNik9Bwv81yU1Wt2ukEfY2Ono kljfrusbSL4k/4xKxIXDKGSmxERt8nA0qHiRgeFunzJHM6R2aqL+9eii9E/mKsU/1z aUYgq+pjAAsZg== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id B5D8F18006C for ; Fri, 5 Apr 2024 10:58:25 +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.0 required=5.0 tests=BAYES_50,DMARC_MISSING, HEADER_FROM_DIFFERENT_DOMAINS,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 gliadin.co.uk (gliadin.co.uk [80.82.115.221]) by php-smtp4.php.net (Postfix) with ESMTP for ; Fri, 5 Apr 2024 10:58:25 +0000 (UTC) Received: from [192.168.0.17] (hari-18-b2-v4wan-169870-cust740.vm1.cable.virginm.net [92.239.242.229]) by gliadin.co.uk (Postfix) with ESMTPSA id C3CD8FA0220 for ; Fri, 5 Apr 2024 13:57:53 +0300 (MSK) Message-ID: Date: Fri, 5 Apr 2024 11:57:53 +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: <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> <8FB87901-02D7-4934-9119-55B21CEDDA9D@sakiot.com> <8035a2b2-f8dc-4a25-98eb-1d19c986bc75@bastelstu.be> Content-Language: en-US In-Reply-To: <8035a2b2-f8dc-4a25-98eb-1d19c986bc75@bastelstu.be> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit From: barney@redmagic.org.uk (Barney Laurance) On 05/04/2024 10:48, Tim Düsterhus wrote: > > Your `Money` example would allow for unsound and/or non-sense > behavior, such as: > >     $fiveEuros = new Money(5, 'EUR'); >     $tenDollars = new Money(10, 'EUR'); > >     $what = $fiveEuros + $tenDollars; > > What would you expect to be in $what? A `BcMath\Number(15)`? > Yep, since the add method is final and will return a Number then Number(15) is the only possible result. And even if you did `(new Money(5, 'EUR')) + (new Money(15, 'EUR'))`, the result would be the Number 15, not a money. Equally if it was extended to add the isPrime method as soon as you do any calculation on it you'd get a number without the isPrime method, so it would be of very limited use. That could be avoided by returning `static` instead of `self`, but that's makes addition non-commutative which would be confusing, and using `new static` sort of requires the constructor to be final, which would make the Money case impossible. So yes I'd say you've convinced me that the Number class does need to be a Final class.