Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:124006 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 A454C1A009C for ; Sat, 29 Jun 2024 00:14:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1719620132; bh=aEaVyvv5zT4huX+IKY2I2YY1Is2QXOPjuf2J/RIRJqs=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=Yb9Z9sBujuFNl8lpCjrhlgFEmy5wrl3EMkI3UwjWwdBfQlFbH2KJwgg52U7OVo8yr qcg7R255AqegOHrcYeHS3+47DcfA+WthRogOEP6G9eB+Uuu1BsGDtGb+D6MtlzhPU8 paVdj3G55Ij6cJ6cYumqV1Sv2MekI3UjTNW2YWmEq0tiNLE/J6+m2mkxEfUGPJvVck F6XsiuzUgtzhDvZom6vlLRINHpzo3On9OY1hUBhbA/VsJpReIEIrpCjbAG36TPRQ5w IFEGC60zq27cOlW7Cmo/Q+ME+HkX8wCFqFco/TUdI1MEYe7BzDPlFNv4f0ee34vw8U 1glPOxZXwiFJw== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 6D7CB18075B for ; Sat, 29 Jun 2024 00:15:31 +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,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: Error (Cannot connect to unix socket '/var/run/clamav/clamd.ctl': connect: Connection refused) X-Envelope-From: Received: from mail-oo1-f52.google.com (mail-oo1-f52.google.com [209.85.161.52]) (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 ; Sat, 29 Jun 2024 00:15:31 +0000 (UTC) Received: by mail-oo1-f52.google.com with SMTP id 006d021491bc7-5c229aa4d35so672308eaf.3 for ; Fri, 28 Jun 2024 17:14:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719620051; x=1720224851; 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=aEaVyvv5zT4huX+IKY2I2YY1Is2QXOPjuf2J/RIRJqs=; b=OsjTAw3WMbwfpedrSiau9b0l/BX9IscQiyA4UOremtx/OoRyda4FOYJ260UxuPJ9Jb U53NhbMQwoTuqOzttYriQmrLOvXsHbr8KBsIKik/yHqoxVOfrWsrlkt1ckgxTnp2CSMG p1fkHZS2Dj9SR1bRT3fxG5RpA5jiUewbDlZTk86gjcTPHlnra5P7KB7hAxBIjSi2qrlb MgStFPad/IkH6gNuK97yI5RX0QNfDYFnePwDYVMcyJ7I5KKr4ZxPhDzj0A1PG2Q5U2Z9 IHPV5/cITB6KB/w4j/mTp4gKn4jhf+8C/Nsh7w6tZ+HpZ4bK94QnFmVXTWcE9Mnn8q51 FPPA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719620051; x=1720224851; 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=aEaVyvv5zT4huX+IKY2I2YY1Is2QXOPjuf2J/RIRJqs=; b=r4PJX7A6g9K3ssrnxqnk4WfkN7x91lhSkdUn3gTpIlYY64SV7MnYLX9KhgHBrntKfH tf8kXEELNraYlEoxx1Mi7GV5ZD9XxDxfi/MEgA/gQs8zjggfUODn0FpSemOKy3hYdyQB 9t0ck2DR7dkV+1O+1mfGXhZGQb/t5pUhKh1PbR7en8uhUVi+q2evfNCMmOaguFs3XADe BmAU69VbjRPUt5XfOlUW89tM2JtplKAY5KUpV/76rF5Ol8uP+tQ3Zakz49z2GRlTRyu8 fIuGjQmyyCl/QrrLb9Jm29b7xqbZf24+Y2qm5NuEBJw9SCjhwAlQb0WwenG71dQ8vfzS rOMw== X-Gm-Message-State: AOJu0YyzSmEwmtOndBss/T37XsS3rJSDss5ATrJ/sgE6HJJeB90k5a9n RsUu5GD4jl89NArgIwcf80W7NquKuPrLfdHyh9/ZVx7Waj6hKYvyiLrD/ePyBnuaTiaWqVBAEs+ MX3RAnssmS/y5gTOrvIbqkfM99txRTA== X-Google-Smtp-Source: AGHT+IHl1HL7UvlEudwRWHehnaQ2kRT57iDMILSd4e13/t9svDtBJbPbnYhWGbhY6xacBuzfzDvn9CaGQBGjaJNni4A= X-Received: by 2002:a05:6358:121c:b0:1a1:fe6f:142b with SMTP id e5c5f4694b2df-1a23fb80594mr1936087655d.9.1719620051186; Fri, 28 Jun 2024 17:14:11 -0700 (PDT) Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net MIME-Version: 1.0 References: <8dc5393e-b552-465a-9237-9251e8bf1001@app.fastmail.com> In-Reply-To: <8dc5393e-b552-465a-9237-9251e8bf1001@app.fastmail.com> Date: Fri, 28 Jun 2024 17:13:58 -0700 Message-ID: Subject: Re: [PHP-DEV] [RFC] Operator Overrides -- Lite Edition To: Rob Landers Cc: internals@lists.php.net Content-Type: multipart/alternative; boundary="0000000000004cbe9b061bfc3e3e" From: jordan.ledoux@gmail.com (Jordan LeDoux) --0000000000004cbe9b061bfc3e3e Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Fri, Jun 28, 2024 at 12:55=E2=80=AFPM Rob Landers wr= ote: > > > 3. The private/protected distinction is fairly meaningless for the > functions that implement overloads, because the privacy of the function i= s > ignored completely when it is executed to evaluate an operator. > > > Hmm. I like the idea of protected, because it gives a structure to it tha= t > is apparent and usable right from the IDE. You just =E2=80=9Cfill in the = blanks=E2=80=9D or > stick with the default behavior. > I do not understand how the visibility has any impact on the usability you are seeking to provide. 4. The `static` distinction is also fairly meaningless, as in PHP there is > no situation possible where an operator overload can occur WITHOUT it > operating on objects themselves. > > > For this, that is the wrong approach. The actual behavior is on the type, > not the instance. The object instances may not even know their value, the= y > merely represent the value. > A GMP object instance that does not know its value? What are you even talking about? Can you show me some code explaining what you mean? I had literally months of this argument for the operator overloads RFC, and studied the overload implementations in six other languages as part of writing that RFC, I feel like I understand this topic fairly well. But I do not understand what you are saying here. > 6. The `comparable` function you propose doesn't actually have an operato= r > it corresponds to. There is no operator in PHP for "is the left value > comparable with the right value". There are operators for comparisons > themselves, which I assume you meant, but a bool is insufficient as a > return type for that. > > > In the engine, there=E2=80=99s just a compare function for internal overr= ides. So > we just check that everyone agrees that the two objects are comparable an= d > then pass it on to =E2=80=9Cbusiness as usual.=E2=80=9D > I'm aware of how the compare handler for class entries and zend_compare interact. What I am saying is that your design is insufficient for <=3D>. Y= ou cannot return `false` from this method to mean uncomparable, and `true` to mean comparable. The zend_compare function can validly return 0 or -1, with the -1 being used for both less than OR greater than because the operands are reordered to always be a less than comparison. Then 1, which normally is used for greater than, is used to mean uncomparable. If you alter GMP so that the compare handler directly calls the class entry for this "comparable" function, you will be mixing multiple return semantic meanings, assuming you can construct a way to make the values normalize. If you implemented "comparable" in the way you are describing, $obj1 =3D=3D $o= bj2 would ALWAYS be true, no matter what their values are, completely changing the meaning of the equality operator for GMP. As you are proposing this without any genuine expectation you can pass it, this will be the last energy I will invest into helping. Jordan --0000000000004cbe9b061bfc3e3e Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable


=
On Fri, Jun 28, 2024 at 12:55=E2=80= =AFPM Rob Landers <rob@bottled.codes> wrote:


3. The private/protected distinction = is fairly meaningless for the functions that implement overloads, because t= he privacy of the function is ignored completely when it is executed to eva= luate an operator.

Hm= m. I like the idea of protected, because it gives a structure to it that is= apparent and usable right from the IDE. You just =E2=80=9Cfill in the blan= ks=E2=80=9D or stick with the default behavior.=C2=A0

I do not understand how the visibility has any= impact on the usability you are seeking to provide.

4. The `static` distinction is also fairly me= aningless, as in PHP there is no situation possible where an operator overl= oad can occur WITHOUT it operating on objects themselves.

For this, that is the wrong approach. = The actual behavior is on the type, not the instance. The object instances = may not even know their value, they merely represent the value.

A GMP object instance that does = not know its value? What are you even talking about? Can you show me some c= ode explaining what you mean? I had literally months of this argument for t= he operator overloads RFC, and studied the overload implementations in six = other languages as part of writing that RFC, I feel like I understand this = topic fairly well. But I do not understand what you are saying here.
=C2=A0
6. The `comparabl= e` function you propose doesn't actually have an operator it correspond= s to. There is no operator in PHP for "is the left value comparable wi= th the right value". There are operators for comparisons themselves, w= hich I assume you meant, but a bool is insufficient as a return type for th= at.

In the engine, th= ere=E2=80=99s just a compare function for internal overrides. So we just ch= eck that everyone agrees that the two objects are comparable and then pass = it on to =E2=80=9Cbusiness as usual.=E2=80=9D

=C2=A0I'm aware of how the compare handler for cla= ss entries and zend_compare interact. What I am saying is that your design = is insufficient for <=3D>. You cannot return `false` from this method= to mean uncomparable, and `true` to mean comparable. The zend_compare func= tion can validly return 0 or -1, with the -1 being used for both less than = OR greater than because the operands are reordered to always be a less than= comparison. Then 1, which normally is used for greater than, is used to me= an uncomparable.

If you alter GMP so that the comp= are handler directly calls the class entry for this "comparable" = function, you will be mixing multiple return semantic meanings, assuming yo= u can construct a way to make the values normalize. If you implemented &quo= t;comparable" in the way you are describing, $obj1 =3D=3D $obj2 would = ALWAYS be true, no matter what their values are, completely changing the me= aning of the equality operator for GMP.

As you are= proposing this without any genuine expectation you can pass it, this will = be the last energy I will invest into helping.

Jor= dan

--0000000000004cbe9b061bfc3e3e--