Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:117728 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 85933 invoked from network); 13 May 2022 12:47:28 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 13 May 2022 12:47:28 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 99E58180384 for ; Fri, 13 May 2022 07:26:58 -0700 (PDT) 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_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS19151 66.111.4.0/24 X-Spam-Virus: No X-Envelope-From: Received: from out5-smtp.messagingengine.com (out5-smtp.messagingengine.com [66.111.4.29]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Fri, 13 May 2022 07:26:58 -0700 (PDT) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id 9F9015C002F for ; Fri, 13 May 2022 10:26:57 -0400 (EDT) Received: from imap43 ([10.202.2.93]) by compute1.internal (MEProxy); Fri, 13 May 2022 10:26:57 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= garfieldtech.com; h=cc:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to; s=fm1; t=1652452017; x= 1652538417; bh=CZ7T8WrmSXfDkrj9SjdTDoltkOP1y1RBIodicw4DbyY=; b=t SumNrM9PEpXjSyd8tzZSAlJKGv9JXkhuGTo2s7baHxek7H6PHQ/ow8WuQzkPD78i rTb6q79aSwX9/pc22ZJrjYxQhn51soygQXhefcoqK68nLjR7qlx4byuGRxdU6kMJ OvLJP+JbnORF40BCGrsMvqBXw12f4G+F+LXJOXEYYewZGu2zNl/Xi8eVBIlfCMzV 9SDVHIamtGFaxC0Duvjj4XSiLoS0T12fa2J7xniwzeztGbARcQm7FisNAlbG00cB Z4vpv3mps8dLZutslotTYHAZLtlUJPbjsNTusMAz8VBp4lY1PM9zskqMhpmL09w+ LK1dInZtmnRTGmOYectrA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t=1652452017; x= 1652538417; bh=CZ7T8WrmSXfDkrj9SjdTDoltkOP1y1RBIodicw4DbyY=; b=x fufhU/vLVO45CVwIGzoc1AVMDVrNnpZ45AquwqoyJ/vLeso/b7Gt6tn6bYPESWAD tQ4mAE4Gy7hL8cmprznt9hO1JUO5TyXxoThpgayvfBFnaxkg2F3oMba5d4nD7GeF drrRX9TRN+F+qLGrDYYZsmyPCqrZYV1m8gBESAaB28udXvCNUViTenUcFQSoLdnm iRszxVRFWVYdG4BUCZDmlXVAnvqc7sl9AMVWPCru64qfMpkfBnbnjnNz8T7m1ljw tZiuIZKpsGEM1js4CsECkLEnzd58FE2+wj40qkzrFWaIgZUP3DmRiu8sN79REp1d ZDlQBe1Ch48e7WFcIpaYA== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvfedrgeelgdejgecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefofgggkfgjfhffhffvufgtsehttdertderredtnecuhfhrohhmpedfnfgrrhhr hicuifgrrhhfihgvlhgufdcuoehlrghrrhihsehgrghrfhhivghlughtvggthhdrtghomh eqnecuggftrfgrthhtvghrnhepgeelgfekudeivddvteffueejffdthfejieevhefgffek udevkedtvdelvddvffefnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrg hilhhfrhhomheplhgrrhhrhiesghgrrhhfihgvlhguthgvtghhrdgtohhm X-ME-Proxy: Received: by mailuser.nyi.internal (Postfix, from userid 501) id 61F782D4005E; Fri, 13 May 2022 10:26:57 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.7.0-alpha0-591-gfe6c3a2700-fm-20220427.001-gfe6c3a27 Mime-Version: 1.0 Message-ID: In-Reply-To: References: Date: Fri, 13 May 2022 09:26:37 -0500 To: "php internals" Content-Type: text/plain Subject: Re: [PHP-DEV] The future of objects and operators From: larry@garfieldtech.com ("Larry Garfield") On Fri, May 13, 2022, at 9:05 AM, Rowan Tommins wrote: > On 6 May 2022 23:16:37 BST, Jordan LeDoux wrote: >>I'm not sure at this point how voters think objects and operators should >>work together into the future. I'd like to see if anyone is willing to have >>high-level discussion about the ideas, instead of picking at the >>implementation or details of a particular RFC. > > > Hi Jordan, > > I like Larry's "4 levels", but I've been thinking that there's some > existing functionality in PHP which takes a different direction: rather > than overloading *operators*, the language lets you overload > *behaviour*. We have magic methods like __get and __call, and > interfaces like Iterator, Countable, and ArrayAccess. Some hook into a > particular function, or even operator, but they're generally described > in terms of what they do, not what they look like, if you see what I > mean. > > From that point of view, overloading comparison and equality > *behaviour* makes sense - it could affect not just the == and <=> > operators, but things like in_array() and sort(). I think this > distinction is more pronounced in PHP than some languages, because the > standard library isn't "self-hosted": a sort() call doesn't literally > compile to a call to $a <=> $b > > It's less obvious how that applies to mathematical operators - should > implementing "addition" allow an object to be used with array_sum() > perhaps? And what about deriving one operation from another, e.g. > $foo*3 running $foo+$foo+$foo, or $foo**3 running $foo*$foo*$foo? > > I don't really have a conclusion here, I just wanted to throw it out > there as a different mental model to consider. Interesting point. I think that's the most compelling argument I've heard for using `public function __lessThan` rather than `operator <`. I'm not sure if it's enough to change my own preference on that front, but it's an interesting point. Working with `in_array()` and `sort()` is a necessary feature for comparison overloading, IMO. I'm unsure about something like `array_sum()`, but could be convinced. Hum. --Larry Garfield