Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:108303 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 89076 invoked from network); 29 Jan 2020 01:49:58 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 29 Jan 2020 01:49:58 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 034C11804F4 for ; Tue, 28 Jan 2020 16:00:30 -0800 (PST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_PASS, SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS11403 64.147.123.0/24 X-Spam-Virus: No X-Envelope-From: Received: from wout3-smtp.messagingengine.com (wout3-smtp.messagingengine.com [64.147.123.19]) (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 ; Tue, 28 Jan 2020 16:00:29 -0800 (PST) Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.west.internal (Postfix) with ESMTP id 3E6EC591 for ; Tue, 28 Jan 2020 19:00:28 -0500 (EST) Received: from imap2 ([10.202.2.52]) by compute4.internal (MEProxy); Tue, 28 Jan 2020 19:00:28 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mjec.net; h= mime-version:message-id:in-reply-to:references:date:from:to :subject:content-type; s=fm3; bh=uz4kh5QuTbZlNsYV0/GEN/0eCMyTsIr CmINMkijMR6Y=; b=KEyEpmaY8dzgoyxT3taDWgTkgvPBUxwn063d+Ju4IFyT2dp cT6eRAfUxYA0EvMrgs/WsTxOLsodVgh/s/F+f1DuU8zX48nXenKQQFjtjd8M3C2y f+9li2q3TUTps4StJYRwfQoZQOzaDaB6H7hbKgo7Q6kRp7NbCptTIiCWyIynpccj JswuwTdqSGWcNO/2j70oFvnSmTNnEX2aDffsGOg4y4WSaYAilE644f4pRza1AdIe l/nW0N1xcUA6ePSonoWHn+aVOdNwQJQpzkIr6loKbvKx0TVWermjnD1Fj88oCnk+ 65JH6/7bl7A4X5a+5MEcj7/5F32E+9/OuP6pSdw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm1; bh=uz4kh5 QuTbZlNsYV0/GEN/0eCMyTsIrCmINMkijMR6Y=; b=Wa/j+QWsm6HDJQJV6N8EDe p2D3iSl4Qh6d16RbuLq/dllH1zGdFYmzLgZRilhLc0iRXrXWik5TTIEJ2Ot6vF3a 8yvAwOqnfRbF8iy85keR+blJXKdhOa5DY0OUotLBgHQxdpti4CEiELBbRUwEswuc Iv9NInDvqhlWW12mhLvTA1EyPO2Y3aqMiGNZ3W9+tljDP7ooaR5V0U//CG3awyka f4rdKE0rxgUt3Aq4Bk13+dyz43t/+ut7Aw/j+3Ipk6s085hhfFMI3L/PYj/LnTMg u/CmVF2BVja0dqaXFoCUr1ypjiSZHqUS/Y/6jHNi0pv6a7g0id7AzpIlx8AkXXEw == X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedugedrfeehgddtkecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhepofgfggfkjghffffhvffutgesthdtre dtreertdenucfhrhhomhepfdfoihgthhgrvghlucevohhrughovhgvrhdfuceophhhphes mhhjvggtrdhnvghtqeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrih hlfhhrohhmpehphhhpsehmjhgvtgdrnhgvth X-ME-Proxy: Received: by mailuser.nyi.internal (Postfix, from userid 501) id 8BA5BE00A2; Tue, 28 Jan 2020 19:00:27 -0500 (EST) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.1.7-781-gfc16016-fmstable-20200127v1 Mime-Version: 1.0 Message-ID: <7109bac3-94ae-4543-8cf9-a303cc749e51@www.fastmail.com> In-Reply-To: <55C25E7C-596F-46E8-A812-A7DF86A17546@benramsey.com> References: <00ea01d5d630$b18d4f20$14a7ed60$@gmx.de> <55C25E7C-596F-46E8-A812-A7DF86A17546@benramsey.com> Date: Tue, 28 Jan 2020 18:59:50 -0500 To: internals@lists.php.net Content-Type: text/plain Subject: Re: [PHP-DEV] Operator overloading for userspace objects From: php@mjec.net ("Michael Cordover") On Tue, Jan 28, 2020, at 18:47, Ben Ramsey wrote: > If you take mutation off the table, then things become easier, IMO. We > only need two magic methods: > > * __toInteger(): int > * __toFloat(): float > > Then, in any mathematical context, PHP could call the appropriate > method and use the number returned in the calculation. I don't think this is enough to make operator overloading useful, even without mutation. For example, the result of TimeInterval(1, 'ms') + TimeInterval(3, 'days') requires more information that we'd get out of __toInteger or __toFloat, but could still be a useful operation to perform, and ought to return a new TimeInterval (not an int). There are many of these tagged-number types where overloading would be helpful. - mjec