Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:115680 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 77484 invoked from network); 10 Aug 2021 00:19:04 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 10 Aug 2021 00:19:04 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id D32C1180088 for ; Mon, 9 Aug 2021 17:49:22 -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.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,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-lj1-f179.google.com (mail-lj1-f179.google.com [209.85.208.179]) (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 ; Mon, 9 Aug 2021 17:49:22 -0700 (PDT) Received: by mail-lj1-f179.google.com with SMTP id n6so13124629ljp.9 for ; Mon, 09 Aug 2021 17:49:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=7TC07CVOz2EpuwCLhSMfPOHaQjNqAnN2Wg0D/PMoA4U=; b=tTLNwNq9dSBYNYuDjKvvfndciCnsWvXbYDC05uV5Mjqw5qHovKIEdQWfXDNaHfjUvh BT6NTl4o7sOHqFwAZ3sL1emxhFyLII9sM9e+4u7TlnN+W7J2Otzl6ODiduuDaJe1v6xB rwt5SE1Igx/BLTit2/tqkcus4GaeEf2vKjIS2XhHIZDCUagCirXHoH3e8O4eAHhtIJWS jJuo/jzkPBoZui+8aqJIdPwYESjtAGQr5p5/GUwb8AB5VM8UpGUuYa/2WCFyzlJQiH5c ydO9tvec3YPH+Xn6lKl73UzFd8upzEzxlE3GHKGfeAJJaRl1pa0b/0ko7giRWDdy14zV A9IA== 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; bh=7TC07CVOz2EpuwCLhSMfPOHaQjNqAnN2Wg0D/PMoA4U=; b=fU9zZBdCMyt+7Pt9l9r6qao7Fq/pC0kI3peeUtuj7gq/Ed9VDOvK0U07CUN8JC9FIg NQgXn/TuDmge39utb77/OHxdb85rlPHdHABrIFqkyL8ZmXYDvtTFRcInrzKWzbJcewV+ 69YeMMHzapYb9tSav8Urf+3d221UMODPYMw78rBu8IL/UO2C5WHivbYji+1pCcJq+Tgs tRchxVbznGvji393vfhAmuym3Aq/8mO7FIA7Lhm4090nZDTCDUmIG4GKIMB0g7049SKo um8cRyBipri0WQqb4E8Y5V/kcJz9uI1uqAOSSfd0Z07RAiZLIMBu3RJFFHyvMHEZX1P4 RYkQ== X-Gm-Message-State: AOAM530TmFsvSLS6LQqwppxwY51MPC+cw2ahBhiDcvWuw9UzehLeNGx0 ta4nckjZh1XsHEB0zV+PYFPLLQbCWrcHiJrAvP+H2By0ZnGalA== X-Google-Smtp-Source: ABdhPJxwQ+N2znYOHsBsddF88eIanPv60/oFdzaULRt21I+z9bYFc/XjF8drBocx6LDqBqj+pQcUAyaTWWUim20ZnKc= X-Received: by 2002:a2e:b0c8:: with SMTP id g8mr15161279ljl.444.1628556560159; Mon, 09 Aug 2021 17:49:20 -0700 (PDT) MIME-Version: 1.0 References: <94696d46-c4e6-406a-b859-89144bff31bf@www.fastmail.com> In-Reply-To: Date: Mon, 9 Aug 2021 17:49:20 -0700 Message-ID: To: PHP internals Content-Type: multipart/alternative; boundary="00000000000043d96405c929dfd9" Subject: Re: [PHP-DEV] Revisiting Userland Operator Overloads From: jordan.ledoux@gmail.com (Jordan LeDoux) --00000000000043d96405c929dfd9 Content-Type: text/plain; charset="UTF-8" On Mon, Aug 9, 2021 at 2:32 PM Mike Schinkel wrote: > However, you are actually making my point, which is that since they are so > deterministic then why is there the need for flexibility to be done in > userland vs. the standardization that could be could be better in PHP core? > For the latter we can ensure the abstractions are not leaky and the > requirements are fully addressed. > > They are deterministic for given *values* and *types*. They are not deterministic over the whole category. > > Why don't we start with this? Rather than initially focus on the syntax > for creating operator overloading why don't we start by focusing on the > known use-cases and come up with documentation showing how those use-cases > would leverage the custom operators? Fully map them out. > > If we do that and we still get general operator overloading then at least > userland will have a roadmap for how to get started with operator > overloading for the known use-cases rather than lots of developers seeing a > shiny new feature that they all start adding to their code, badly. > > You can easily create this doc on GitHub and solicit PRs from others far > and wide for their use-cases. > > I have the stub RFC on github: https://github.com/JordanRL/operator-overloading-rfc However your suggestion is an excellent one. I will add some interfaces and abstract classes to that repository when I am able to illustrate what user implementations (or the PHP expressions of the C implementations) might look like. > > It would help me if we could discuss this in specific terms rather than > abstract terms. What does "fully-featured complex number library" mean? > Can you create a Gist showing what the class interfaces would look like in > PHP code? > > I mean that it would need to be a complex number literal or object that fully understood its relationship to other literals and to the operators. The interfaces, if you ignore typing, would be similar to other number classes, but the *implementations* would be very different. That's the biggest problem with providing say a single abstract number class that has built in operator overloading. Unless it can then be extended and overridden, in which case it seems that it will result in much more heinous misusage to me than simply doing generic operator overloading. > > Correct me as I may be wrong, but isn't int+imaginary a function of (r, > theta) and vice-versa? > > If yes, I assume that both representations could be generated by the same > ComplexNumber class? > > Yes you're correct. The values of both representations are computed when changed in my own ComplexNumber class, and the most advantageous one in terms of algorithmic complexity is used for calculation in any given method. > > The custom operator overloads in C require a lot more skill and experience > to implement than in PHP which I am arguing is a benefit related to > operator overloading. > > Further, only people who are not using managed hosting that constrains the > extensions used are able to use these extensions. So these overloaded > operators are not infecting PHP code far and wide. > > The overloaded operators don't interfere with anything *at all* unless you use an object that has them defined, even if you use the extensions. The GMP operator overloads don't affect anyone unless they are using GMP. These will be the same, in that the operators are unaffected unless a class opts in to using the feature. > > We have differing opinions on that, so we should agree to disagree on that > subjective assessment. > > Alright. > stdClass objects also support equals comparison so really this is more > about add, subtract operators which DateTime and TimeInterval do not have. > > Which brings up this question: If we allow comparison operator overloading > for objects does that DateTime comparisons might no longer mean they are > the same pointer but instead a userland comparison? If yes, that actually > chills me to the bone. > > https://3v4l.org/2RCot#v8.0.9 > > The identity comparisons (`===` and `!==`) were two comparisons that I specifically planned to exclude from this RFC. > > That's absolutely fine and understood. That's the way it works for PHP. > > Similarly I will advocate others consider fleshing out specific use-cases > and ideally have us implement a few before we consider adding generic > operator overloading to PHP. > > Unless of course I find that there is a strong consensus to move forward > with generic operator overloading in which case I will demure. But thus > far it is not clear which way that wind actually blows. > > And I wouldn't expect it to be clear at this point. I was reaching out now more to gather a list of preferences and concerns for the feature. Perhaps the best way to think about what I was looking for was the answers to these questions: 1. If anyone planned to vote against such an RFC regardless of implementation, details, or need, why? Could I understand what those concerns are. 2. Supposing that the feature were guaranteed for inclusion, what are the preferences of the people on this list for limitations, implementation details, and structure. 3. If anyone with deeper knowledge of the PHP source had some pointers for me on auxiliary things that would need to be changed with this RFC, I was hoping they would be mentioned. (For instance, I'm aware of DateTime's overrides and did not plan on converting them to extendible generic overrides.) > > Given our dialog, maybe we can meet half-way? Since it's a year out as > you say, why not go ahead and start documenting the use-cases and how > operators would be used for those use-cases? > > Like I said above, that work will need to be done by someone eventually if > generic operator overloading is added; better to do it once and share than > have each developer have to redo on their own. And I might even become more > supportive if I can see that choices that need to be made regarding > operator overloading are more obvious than I am currently assuming. > Yes, I have the stubs of that work outlined in the RFC github I linked, and I will put some effort in over the next week to create some mock classes and interfaces to illustrate the use cases. Jordan --00000000000043d96405c929dfd9--