Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:122997 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 CE8BB1A009C for ; Sat, 6 Apr 2024 13:10:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1712409032; bh=qXcvKGatd/YA+VenAmxP5q5RIi6pF6tjMoQOZ0yxZOc=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=ELa0bBkO3MKorqBZHsrPjpwnb9pvUGP+ckJbj3NqqyYzSMYWpTOez3PTNy0+geQf8 I+LW0jbs116+tGDfxFAFOb7xpgp+M4VQD9dum9dIgDQhJGJcpGxC8JOxOvKiFdbENp d2HPTulGPUOOFTg0SAUp90E5HT4C3utZZ2pzNtJuqb8QsaaIMvPrwBfQbdJtUz26IE eViZsQCQfnv4S4Np7mGXgBBcFGRAKXBSlotFl+FyZ5ll24/WgFLfcMkB4HYWRPyIzH V7ZEkqm+oLCQX5XabUEdsNEW8fqc/MRQfsXpOL3TXtC0HG9USEK+TKeUSytb6Fbnc+ Izn2hhWZQ8GUQ== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 5EC771801E3 for ; Sat, 6 Apr 2024 13:10:32 +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 chrono.xqk7.com (chrono.xqk7.com [176.9.45.72]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Sat, 6 Apr 2024 13:10:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bastelstu.be; s=mail20171119; t=1712409000; bh=+4eZ0n1NKgXpEyWHrqjYD5q+KLmqy7l9oG0XVYZcEiU=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type:from:to:cc:subject:message-id; b=ccr5qF1B6ZE1tMujsURKJXnL2RvbT3QbG5zQqA4U6n/Z3a1sVc/5jj62m8GSc55eW Agl7wBhM6BnhjvPaOo4bX/Pl+kNtrlwGm2VBKniTv5iJ8qp8/m/XZWsgIXiNOMViuk e1i2v73sk8ZIc0BMy8htSywbkeImL2cMtQnewf7sFrWcef9LE9xIh05L+nGHq6s4X5 cT/saAiENZL6CDKUlj9gYsc++jC/tPjdlfhgkoe+ZpCukoolrojia5bu6P6ebidUB6 OefTbpYSPMCd6raGR9jRvbxh2TPCGTbdLgtsQRZPrpgvE+ni6D1I7oya3Y+vNxugFd UCL1Rm2V+KGiw== Message-ID: <5ce49f0f-7fee-4317-80bf-fbee21a83e4b@bastelstu.be> Date: Sat, 6 Apr 2024 15:09:59 +0200 Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net MIME-Version: 1.0 Subject: Re: [PHP-DEV] [RFC] [Discussion] Support object type in BCMath To: Jordan LeDoux Cc: Saki Takamachi , Lynn , Aleksander Machniak , php internals References: <46B14427-44B2-4665-BC14-6018AC34B0CF@sakiot.com> Content-Language: en-US In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit From: tim@bastelstu.be (=?UTF-8?Q?Tim_D=C3=BCsterhus?=) Hi On 4/5/24 22:04, Jordan LeDoux wrote: > That is an absurd example. Why would anyone use inheritance for that class > design? If what you are arguing is "if you look at use cases where > composition is clearly the correct choice then inheritance causes > problems", then I'm not sure what the point of the discussion is. > Okay, then please tell me in which use cases inheritance rather than composition is the right choice? For the "Money" example, I've already showcased how it would be broken and I can't think of any example where inheritance would be superior to composition. Yes, my example is dumb, but nevertheless it showcased that the native and unchangeable operations would be unsound for child classes with custom properties, because the operations would not be able to correctly fill in the custom properties. And even without custom properties, the behavior would be unsound because the class name acts as an implicit unit: $twoMeters = new Distance(2); $fourSquareMeters = $twoMeters * $twoMeters; Multiplying two distances does not result in a distance, but rather in an area. Making it a Distance(4) would be incorrect. So, which use case would be enabled by allowing inheritance without being subtly broken by being unable to override the native operations? As I've said yesterday in Stack Overflow chat: "Operator overloads through a backdoor are even worse than actual operator overloads". Best regards Tim Düsterhus