Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:115651 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 16920 invoked from network); 6 Aug 2021 19:49:10 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 6 Aug 2021 19:49:10 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 41B371804AA for ; Fri, 6 Aug 2021 13:18:40 -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=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HTML_MESSAGE,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2, SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS15169 209.85.128.0/17 X-Spam-Virus: No X-Envelope-From: Received: from mail-lf1-f51.google.com (mail-lf1-f51.google.com [209.85.167.51]) (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 13:18:39 -0700 (PDT) Received: by mail-lf1-f51.google.com with SMTP id g13so20162959lfj.12 for ; Fri, 06 Aug 2021 13:18:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paragonie-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=TV1+EroiFMIBoJfaHix5vYJGlW0nxCJuXoyIy4bdtr0=; b=bkPvUmNMjJA225PjTY8aiHmInTnECE+POXX85Leyekd9geuJw4EyQzcWuznl3GBR8W 5JaeizTRdzLeyUVxx2LW4nHVzlmFrmcIDxnUsyd35Sk0bZQnknsv1jsh28Y4FCZ+PrAv mO30hCtGW7DYDf0K4nTVI6Eaq7BlNVmXd0Qox46kFMQS6nqyJTWV0NJXZ7J5ppCiQd9l +uAIOw+R8Ub9Mvww4cIE4XIt4H/BzvubgoL/zqx2F4nOjIMf+M6FF6F1jtA+bhfc5cpO slJL5GhHywYh2yr+3rpV5YTA3+RsuhBxWoLjTmC1hBw67K82fbD6s9BDPMTtsMCMDtB2 Jfiw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=TV1+EroiFMIBoJfaHix5vYJGlW0nxCJuXoyIy4bdtr0=; b=Xua8WnmUbrj93bXsFXdYFb0+SLkCkzW4o40ZvyKnTtQZcYyH9MTWyUtuVA4zJGQeCX is0CRY7IXnokvhzBiueMkXV4lebyUsKazShcqRBx9wp0xeU+dAobaP7y06Ba0eT5SKAj EfKiqriKxO4eGKKMLhUU22M15atnAB3BxxHdRgkca17Cu3sDlqQWxfLqY5CF75nWlmDN BPWM+76bhKWxvRid1TvKWJf4gV3NlUOOle3jH0lqoIjRHdybZVAuwKU6CusavQcXyd0/ MXEuPVoEqK7RudGrE+psCOCVohEah1yFqJGJLBXZTXlFQS6t121vFzbRGT8NiagDOx/n pfOg== X-Gm-Message-State: AOAM531oi7VTqZMVyQJCRKbxmS+Hl6CPdKsMWgvhtjV+Fb2QD2d+53Wr rIDBdsKnnF45K3R9z9TETQmA2YYsEzVggh/9ypPyCaxT3ec= X-Google-Smtp-Source: ABdhPJyikOQHFOhe0SpCg/XARtR7LEc4sAMgzNf+nk5sQ5Hv6mFAOWS0uv0iliknDE7CMRizRgOgce7cz9eIsrX0VwM= X-Received: by 2002:a05:6512:14c:: with SMTP id m12mr9071392lfo.257.1628281117284; Fri, 06 Aug 2021 13:18:37 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Fri, 6 Aug 2021 16:18:27 -0400 Message-ID: To: Larry Garfield Cc: php internals Content-Type: multipart/alternative; boundary="000000000000972c8205c8e9bd1d" Subject: Re: [PHP-DEV] Revisiting Userland Operator Overloads From: scott@paragonie.com (Scott Arciszewski) --000000000000972c8205c8e9bd1d Content-Type: text/plain; charset="UTF-8" My recommendation is to have a base interface for every operator that can be overloaded, so that these can be composed together. AddOverloadInterface { __overloadAdd(): self; } SubOverloadInterface { __overloadSub(): self; } MulOverloadInterface { __overloadMul(): self; } DivOverloadInterface { __overloadDiv(): self; } ModOverloadInterface { __overloadMod(): self; } LeftShiftOverloadInterface { __overloadLeftShift(): self; } RightShiftOverloadInterface { __overloadRightShift(): self; } XorOverloadInterface { __overloadXor(): self; } etc. Then if you were implementing matrix math, you could do this: MatrixMath implements AddOverloadInterface, SubOverloadInterface, MulOverloadInterface { } This prevents you from having to define methods for operations you don't support. It's probably worth exploring whether common combinations are worth defining for convenience. On Fri, Aug 6, 2021 at 1:49 PM Larry Garfield wrote: > 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 > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: https://www.php.net/unsub.php > > --000000000000972c8205c8e9bd1d--