Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:115649 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 3550 invoked from network); 6 Aug 2021 17:19:51 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 6 Aug 2021 17:19:51 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id F10D31804C8 for ; Fri, 6 Aug 2021 10:49:23 -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.6 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL, SPF_HELO_PASS,SPF_NONE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS11403 66.111.0.0/20 X-Spam-Virus: No X-Envelope-From: Received: from out1-smtp.messagingengine.com (out1-smtp.messagingengine.com [66.111.4.25]) (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, 6 Aug 2021 10:49:22 -0700 (PDT) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id CFE3D5C010F for ; Fri, 6 Aug 2021 13:49:20 -0400 (EDT) Received: from imap43 ([10.202.2.93]) by compute1.internal (MEProxy); Fri, 06 Aug 2021 13:49:20 -0400 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=fm3; bh=y+yYa5 8pV/gpDQtnW48L555i43Hm0aiY6syqyfPqcA8=; b=j3kBxXl5/PtKCYd7v+6JqN eE+kj1G6cmnPaVflvG35uloV0AcNF/0k3onui0fewbZCsF1kSh9jM8shi4kalA2B k/yVWlSeULEbCqrvQMz53NfJcw5JiBsIYMCgBiwt+E6AfVakqMjGjfye8p3oMsAK YzL+rW4p9Xm/dVVREm9ugsCgjcQTk5MTavKd6R/rRF8YEEleNvpw7EWkrQlZF1X5 giVbc3g1CHGHWTFTL0hbD+iziGq1o3t8eVEkcxMwLk/EraKUGqrvUwVhSHCgQ2tL Vg00Mylk6eSKwpUht7PfD957BbSrC8mgfNyP+0ALTChHgUwX6Rvi5nMBJwcxd5Vg == X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvtddrjedugdduudegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepofgfggfkjghffffhvffutgesthdtredtreertdenucfhrhhomhepfdfnrghr rhihucfirghrfhhivghlugdfuceolhgrrhhrhiesghgrrhhfihgvlhguthgvtghhrdgtoh hmqeenucggtffrrghtthgvrhhnpeeglefgkeduiedvvdetffeujefftdfhjeeiveehgfff keduveektddvledvvdfffeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmh grihhlfhhrohhmpehlrghrrhihsehgrghrfhhivghlughtvggthhdrtghomh X-ME-Proxy: Received: by mailuser.nyi.internal (Postfix, from userid 501) id 7CADAAC0DD0; Fri, 6 Aug 2021 13:49:20 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.5.0-alpha0-552-g2afffd2709-fm-20210805.001-g2afffd27 Mime-Version: 1.0 Message-ID: In-Reply-To: References: Date: Fri, 06 Aug 2021 12:49:00 -0500 To: "php internals" Content-Type: text/plain Subject: Re: [PHP-DEV] Revisiting Userland Operator Overloads From: larry@garfieldtech.com ("Larry Garfield") On Fri, Aug 6, 2021, at 11:34 AM, Jordan LeDoux wrote: > Hey all, > > I contacted Jan a few days ago to ask if they were going to try again for > their RFC, but I wanted to get a quick temperature check on this. > > I would like to work on this RFC for 8.2, and after going through previous > discussions on the topic, I feel like the right place to start is to limit > the RFC to only the mathematical operators at first. > > Based on previous comments, I was considering working from Jan's previous > implementation with these basic changes: > > 1. The only supported operators in the RFC will be the mathematical > operators: (+, -, /, *, **, %) > 2. The RFC would also provide an interface, (something like > MathObjectInterface), that has all the magic methods in it. > 3. The do_operation would be changed to check for the interface being > implemented instead of the specific method. > > All of these operators belong to the same "group" of changes, and (broadly) > any object that is valid to override for one of them should be valid to > override for any of them. NOTE: There are edge cases of this statement > certainly. > > This would help address some of the concerns that were expressed about > misuse of things like the + operator to add things to a cache. It would > more explicitly take a position on how these operators should be used in > userland code to keep them more consistent with the behavior of these > operators in normal PHP code. > > This would be my first contribution and my first RFC, so I wanted to get > some very broad feedback on this before diving in. > > It would suggest that future sets of operators could come with their own > interfaces to also attempt to guarantee an all-or-nothing approach in > userland code, (BitwiseObjectInterface, ComparableObjectInterface, > LogicalObjectInterface, etc.). Though decisions on any of those operators > or their implementations would be left as future scope. > > Jordan If you wanted to cluster them, I would strongly recommend much smaller groupings. IMO, adding two collections to get another collection -- like we add/merge arrays -- is a completely reasonable thing to do, but would only use + and potentially - (for removing items from a collection and returning the smaller collection). But * and / make no sense in that context. Even if you confine yourself to mathematical concepts, matrix multiplication is a well-established thing that would make sense for math-centric applications to do. But matrix division is... somewhat more fiddly, and has multiple possible definitions. (Note: I've not done matrix math in over 20 years, so I'm basing that statement on some quick googling.) So I don't think force-grouping the overloads makes sense, in practice. I'm still open to operator overloading in general, but I don't think the clustering is going to help. The weird and complicated type interactions, particularly when it comes to commutablity, are a much larger issue, IMO. --Larry Garfield