Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:116816 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 65487 invoked from network); 5 Jan 2022 13:26:18 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 5 Jan 2022 13:26:18 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 36D51180511 for ; Wed, 5 Jan 2022 06:33:45 -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=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE 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-vk1-f180.google.com (mail-vk1-f180.google.com [209.85.221.180]) (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 ; Wed, 5 Jan 2022 06:33:44 -0800 (PST) Received: by mail-vk1-f180.google.com with SMTP id u1so22637127vkn.10 for ; Wed, 05 Jan 2022 06:33:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dqxtech-net.20210112.gappssmtp.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=inA3OuxtyYIwZ5ee48jCX61IYxJ+t2eLMilT2KoP7l8=; b=n9+UpArP943C3+1S7JQdmCNU/1NhmoxsYH46YISqWQ3MgsIZwoH6vchkmUE/4tYvdv +Ih1c4NFXaoqH54LakWIh3vGnViGQm84GC760nityNWzmUcpPFiL6TiVkt7s2dtnCVwl CsOV48rr2i1EKKPObg/JZ9xkt6nXUV7Ym3z5dkXBjbrpGSSUkDJYbVXgmE/grL4j/aQS A9Lup9gEoPR6G9r1u+LfsRbH5aNDdThz29nlxxQomYvTS4EPpGWjAOoXx3PYRSL+RR+C dT1f/medE6oeERLNoZQCL3vP47ounzJchG7/lcl79Kk8DNtE7tYILKWjMWF1ukA4ZEc8 guLw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=inA3OuxtyYIwZ5ee48jCX61IYxJ+t2eLMilT2KoP7l8=; b=MHFUPy0rPNn2h2VM0naAe/RlsZRyG4Pb1bl1OxB2kY/ZexZrwhB601L6DmpsKHyMgC OtseqBJFQ6mNfMjq4Zo1Y7LBGQgWTHYfjQk6BVTsNb3lzxXpOixg9l+fnK75PAeMyCJL 54T9ewPiokWVSVF/vOGhlf6xbmwFjdq11WINk5PJnsNosKOf2BqHR8dB+h2Ne3RMGaYg kCIciuMZA+2EVeifUptEKumLwVEuoEkoAWJMMvtewdAJThw7rHsZ4T9Greac5vKXUIt/ I8cHOt6jqm9HnqCY0VNLD7zli/x9VPzhW7qPchZCz+1ycCsybH5t7BPusiWJE/AihP1e lQqQ== X-Gm-Message-State: AOAM532mFjldGf+qin8aoeYp7DMyJp6JkskyhWfH3piZ+xS6Tce6/Ny7 Uq5jC6E+cHX9/vZMseFc4jMRKCfHehrRw+B+99WyUQ== X-Google-Smtp-Source: ABdhPJwfXTVx8Pfn0PgCsJ0V9VRYIzUAJbZ+/OnwM9V2Z63vzJ3z7hjUiOBcxpeo4Y/8piIIOXouz98YruORuwesqqw= X-Received: by 2002:a05:6122:b64:: with SMTP id h4mr19076300vkf.24.1641393223879; Wed, 05 Jan 2022 06:33:43 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: Date: Wed, 5 Jan 2022 15:33:32 +0100 Message-ID: To: Jordan LeDoux Cc: PHP internals Content-Type: text/plain; charset="UTF-8" Subject: Re: [PHP-DEV] [VOTE] User Defined Operator Overloads From: andreas@dqxtech.net (Andreas Hennings) Hello Jordan, do you have any thoughts about these symmetric/left/right modifiers, to get rid of the $operandPos parameter? To me, the parameter could be the kind of thing where in hindsight we ask "why?". Also, can we drop the "public" modifier, if we do a new version of the RFC? Cheers Andreas On Tue, 4 Jan 2022 at 00:27, Andreas Hennings wrote: > > Hello Jordan, > > I have another note about the RFC. > (I am not sure what's the policy, if we should continue _all_ > discussion here or go back to the RFC thread. Hope it's ok here.) > > OperandPosition::LeftSide > OperandPosition::RightSide > > I wonder if this is the best way to model this. > Especially, it does not account for the case where an operator only > works in one direction, or the allowed operand type is dependent on > the direction. > E.g., (Money / float) is ok, but (float / Money) probably not supported. > Or if it is supported, then the return type will be quite different. > You can throw an exception, but this is not useful for static analysis. > > An alternative syntax with a few more keywords: > > abstract class Money { > symmetric operator * (float|int $other): Money; // Commutative. > left operator / (float|int $other): Money; // Only $a / $b allowed, > $b / $a not possible. > left operator - (Money $other): Money; // $a - $b > right operator - (Money $other): Money; // $b - $a > } > > Btw, in the Matrix example from the RFC, under "When will $operandPos > be useful?", the $operandPos is not really useful, because it will > always pick the default $a - $b version. > The same applies to "-" operator in my Money example, because $other > already implements the operator. > > The $operandPos is only needed if the left operand does _not_ > implement the operator. Which is the case e.g. for complex numbers, or > the Number class from the RFC example. > > I am trying to think of cases where ($a $b) would have a > different type than ($b $a), but I can't think of any. > Or rather, for any case that I could think of, the mirror operator > could simply be provided by $b. > > I am not married to the modifier names, e.g. it could be "symmetric" > or "commutative" or something else. > For left/right perhaps I prefer to talk about the "default direction" > vs the "flipped direction", not sure how this could be turned into > keywords. > If we don't like more keywords, perhaps something like "!operator" for > the flipped version? > > Cheers > Andreas > > On Mon, 3 Jan 2022 at 01:14, Jordan LeDoux wrote: > > > > Hello internals, > > > > I've opened voting on > > https://wiki.php.net/rfc/user_defined_operator_overloads. The voting will > > close on 2022-01-17. > > > > To review past discussions on this RFC and the feature in general, please > > refer to: > > > > - https://externals.io/message/116611 | Current RFC discussion > > - https://externals.io/message/115764 | Initial RFC discussion > > - https://externals.io/message/115648 | Pre-RFC discussion and fact-finding > > > > Jordan