Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:125604 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 1A03E1A012F for ; Tue, 17 Sep 2024 21:04:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1726607217; bh=EF4Od4BUHwy2wPNflwYWJ5Clpfhc3Let7tHdn1Rqun0=; h=Date:Subject:To:References:From:In-Reply-To:From; b=b+69Qqvqmx08iws/0blr1VXTcXfxpa7t7Y5NwW4+BHz/rflkvlOJIdwTWmCEhq1Pm hlTNTSzAFRrC/Ne4Yyh6ZbWWZeSoUB7BEKGrKpAixqXPxKCc9RfRYZmtxYdukxSv7x gybmAOysrl5ySJwwIjM6SRMHycoOJr7NQYrsfJhf0PhEo6dOTyo6xWfF/osm73rI7u KcECD17vGKQEhygv9+JVJZyYnANNppYWd3bRoMsJQsf1c2qm/BLfk5F+7NmO1LMUbY J3ha6ihUtdbT/hgW16gohfg4iisCMtUNP4Q1Vwrru8EetHy0lSY6QVEojy76ZQQppm 8Tye7rg/w8zfg== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id D3E01180081 for ; Tue, 17 Sep 2024 21:06:53 +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.8 required=5.0 tests=BAYES_50,DMARC_MISSING, SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from jessie.smtp.mailx.hosts.net.nz (jessie.smtp.mailx.hosts.net.nz [43.245.52.195]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (prime256v1) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Tue, 17 Sep 2024 21:06:52 +0000 (UTC) Received: from 125-239-198-3-fibre.sparkbb.co.nz ([125.239.198.3] helo=[192.168.1.67]) by jessie.smtp.mailx.hosts.net.nz with esmtpsa authed as varteg.nz (TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_128_GCM:128) (Exim 4.96) (envelope-from ) id 1sqfNM-00Fz1E-20 for internals@lists.php.net; Wed, 18 Sep 2024 09:04:44 +1200 Message-ID: <95d1a090-83b3-452e-807d-7dbcdf30e745@varteg.nz> Date: Wed, 18 Sep 2024 09:04:30 +1200 Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PHP-DEV] [Pre-RFC Discussion] User Defined Operator Overloads (again) To: internals@lists.php.net References: Content-Language: en-GB In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Hosts-DKIM-Check: none From: weedpacket@varteg.nz (Morgan) On 2024-09-18 05:43, Jordan LeDoux wrote: > > > The problem I was trying to solve involved lots of things that cannot be > represented well by primitive types (which is presumably why they are > classes in the first place). Things like Complex Numbers, Matrices, or > Money. Money can be converted to a float of course (or an int depending > on implementation), but Money does not want to be added with something > like request count, which might also be an int. Or if it does, it > probably wants to know exactly what the context is. There are lots of > these kinds of value classes that might be representable with scalars, > but would lose a lot of their context and safety if that is done. Even plain addition with plain numbers can be fraught. Cardinal numbers (1,2,3...) can be added to and subtracted from each other. Ordinal numbers (1st,2nd,3rd...), on the other hand, cannot be added together and subtracting one from another results in an interval, not a number (which means that addition involving ordinal numbers means things like ordinal+interval=ordinal). Then there are quantities. Quantities of arbitrary dimension (length, duration, monetary value...) can be multiplied, resulting in a quantity of a new dimension, but only quantities of the same dimension can be added. > > On the other hand, Money would probably not want to be multiplied with > other Money values. What would Money squared mean exactly? Things like > this are very difficult to control for if all you provide is a way to > control casting to scaar types. > While I can't think off the top of my head of a case where money quantities might be multiplied by other money quantities, I can think of situations where one might want to _divide_ them...