Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:125561 X-Original-To: internals@lists.php.net Delivered-To: internals@lists.php.net Received: from php-smtp4.php.net (php-smtp4.php.net [45.112.84.5]) by qa.php.net (Postfix) with ESMTPS id A500D1A00BD for ; Mon, 16 Sep 2024 07:48:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1726473018; bh=PXBFE9ycrKLws7l7Rcg7FJcYbpD1aH9ynf7uNxVXkwg=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=AzpCMGnh/7IzuL9LiP+9KRhl3l1HkR5Y1AjcOIOgErPXw4EZPR6vLYMB2M32BoMr3 b7c0WhNfj8WT1JPKXQD2Pd4+yUKTTvAUxzGeMa7jP6JCfUGnPExJQeIs8F6V4OTdI8 XqiaXgbjxCBHl/72VEQ6SRwwG8oQSRiuWOJPEVNHJ5mj5DnWczsSdqFbuvNFSRAyY/ prnWEHr/xm30tLxwVPJ+/GjSlEyEuf5BQHIXLzLSERtuXupG8ElnKLvJLHuAGyZNw6 PuRFOE7XZ+C/p9mMD1KUD9HGyqjEWUmr2Il/fSNbDHkwzwCejfaqP8/mDPAQpJBgAB qfJX+7BqgHkyA== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 321BA180054 for ; Mon, 16 Sep 2024 07:50:18 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=0.6 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,FREEMAIL_FROM, HTML_MESSAGE,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL, SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from mail-pf1-f170.google.com (mail-pf1-f170.google.com [209.85.210.170]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Mon, 16 Sep 2024 07:50:17 +0000 (UTC) Received: by mail-pf1-f170.google.com with SMTP id d2e1a72fcca58-7178df70f28so3117367b3a.2 for ; Mon, 16 Sep 2024 00:48:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1726472892; x=1727077692; darn=lists.php.net; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=PXBFE9ycrKLws7l7Rcg7FJcYbpD1aH9ynf7uNxVXkwg=; b=ceDhJDw1wlvqPML90xe1hZCYLJyMsIWBJtJ0MNvISEpbXDQc38zeFYf2OBQHPv9S9+ O5Jm7x+vzqJjfRVHm6ad7jDSKsifoaZ0WkTvSMP1aOP0vYcEmFhXAy6rn5KFj1FMOCvz WIY1RL3wsfCazlSGnzlzIaBi/5KKvEQnF2/0yeu3InPFqhQuDAb3BRic5hiMuDIeoZMu YD+uBYRPGu/Yfb1utCS7lM/FZceskbY9xWdB7DPakZwWeOVQDm7TwkJePjixBe8PEw0z QvrX9YmKdjB5PJoGEb0kfNLkgjG1u3EflSdkUdMVi1NDDBcunXzHi/yoDGUw3VmgpK+k +ceA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726472892; x=1727077692; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=PXBFE9ycrKLws7l7Rcg7FJcYbpD1aH9ynf7uNxVXkwg=; b=w1ab/jkN8qadV+V9uPNQuknJW1hYSJ0kAyrNqr99NoP+0kgWaH3umHGNc/Ko99w7wm uGeXPE1UL+4nVqymvcNi9iV8FDNoxzBQlU3cElbSdJ1OBbhoq+P+jjbFSFBuKCxMTRf3 CCiAWcLAT8+gC1ocpnRcgGBbvPZtbrKQOeSjmUmc75dye/c6UItTIlxCUT4iEKCN26uU iiBPBfE6gqHL2fr2/CTzNHnVmnxgR8N152CMYVFd/w0Yelf5w3fPBWrePQSwZoU5vgk4 +zKC1P0HiXhJSjw/0C8xzOnm6j7FvusySigcwRi0zqlqcSK8m77DbjuchdK74nrBD0Z5 KLvw== X-Gm-Message-State: AOJu0YzKTiqpGlmEuK8eHOJK0RmDi5fGQEvvdKQAcT+wE08q10CJSg/c FjnZJvNu2NVcinhrFj5fCbhFW5fD7Lr1MahyJok3HzAJGUA5aN9+nghxCV9nvI0aWE1tYlOcwF9 6FPSWo2XkGoMalefl6I9SiN1uPDu4Nw== X-Google-Smtp-Source: AGHT+IGL4nA55LLReQ97IjvDGVhgporUdnUoy5381uVIlf0FrGDOmYkqmLcMf10XYL6Bx4KMWS7ElegUg0iLLinbqJg= X-Received: by 2002:a05:6a21:78c:b0:1cf:47b3:cbbe with SMTP id adf61e73a8af0-1cf764c29f1mr22503808637.45.1726472892082; Mon, 16 Sep 2024 00:48:12 -0700 (PDT) Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 References: In-Reply-To: Date: Mon, 16 Sep 2024 00:47:58 -0700 Message-ID: Subject: Re: [PHP-DEV] [Pre-RFC Discussion] User Defined Operator Overloads (again) To: Larry Garfield Cc: php internals Content-Type: multipart/alternative; boundary="00000000000072723b062237cbd8" From: jordan.ledoux@gmail.com (Jordan LeDoux) --00000000000072723b062237cbd8 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Sun, Sep 15, 2024 at 9:12=E2=80=AFPM Larry Garfield wrote: > > The "multiply by -1 for <=3D>" bit I don't fully understand the point of. > The RFC tries to explain, but I don't quite grok it. > > I will perhaps respond with more detail to the rest of your message later, but I wanted to address this specifically, because I also feel that the original RFC I wrote didn't explain that well. The situation this bit was referring to is as follows: You have an object Foo that implements an overload for the `<=3D>` operator= . The proposed signature for `<=3D>` was simply: `operator <=3D>($other): int` This operator did not have an `OperandPosition` argument. The reason for this was to prevent developers from creating situations where `5 > $foo` is true and `5 < $foo` is true. Instead, internally it did the same sort of reordering that the engine currently does. It calls the implementation the developer defined, and then checks if the object that the implementation was called from was on the right side of the operator. If it was, then it multiplies the result of the user defined overload by -1. Multiplying the result of the overload ONLY when the overload is called for the right side is equivalent to flipping the order. So `5 > $foo` is multiplied by -1 and then evaluated as if it were `$foo < 5`. This is an edge case, but it was an important one in my mind. It would be entirely unnecessary if we allowed the `<=3D>` overload to know what position it was in, but that would enable lots of developer mistakes in my mind for no real gain. Instead, developers should just implement the overload as if the object assumes it will always be called from the left side of the comparison. Jordan --00000000000072723b062237cbd8 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable


=
On Sun, Sep 15, 2024 at 9:12=E2=80=AF= PM Larry Garfield <larry@garfi= eldtech.com> wrote:

The "multiply by -1 for <=3D>" bit I don't fully unders= tand the point of.=C2=A0 The RFC tries to explain, but I don't quite gr= ok it.


I will perhaps respond with more detai= l to the rest of your message later, but I wanted to address this specifica= lly, because I also feel that the original RFC I wrote didn't explain t= hat well. The situation this bit was referring to is as follows:

You have an object Foo that implements an overload for the `<=3D= >` operator. The proposed signature for `<=3D>` was simply:
`operator <=3D>($other): int`

T= his operator did not have an `OperandPosition` argument. The reason for thi= s was to prevent developers from creating situations where `5 > $foo` is= true and `5 < $foo` is true. Instead, internally it did the same sort o= f reordering that the engine currently does. It calls the implementation th= e developer defined, and then checks if the object that the implementation = was called from was on the right side of the operator. If it was, then it m= ultiplies the result of the user defined overload by -1. Multiplying the re= sult of the overload ONLY when the overload is called for the right side is= equivalent to flipping the order. So `5 > $foo` is multiplied by -1 and= then evaluated as if it were `$foo < 5`. This is an edge case, but it w= as an important one in my mind.

It would be entire= ly unnecessary if we allowed the `<=3D>` overload to know what positi= on it was in, but that would enable lots of developer mistakes in my mind f= or no real gain. Instead, developers should just implement the overload as = if the object assumes it will always be called from the left side of the co= mparison.

Jordan
--00000000000072723b062237cbd8--