Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:123993 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 C93DB1A009C for ; Fri, 28 Jun 2024 18:39:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1719600064; bh=W/n1q/bCdBJUNV3cO1UsJZVBcb3nDcAQJ85bq8ogt0s=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=mi8NdIk5r5HI8crh9LGk4e2vyYVlBFKyHFwO1X8iBn4AtaS7kvtxr2kOvLyK0uXTI X+H729Vr/zMpMPQmR50U0ZEFQrm2CN4frsQno8GF6+/B9+mBkR5BM9LvvXfAAzSbgQ Ocl6t6DgJqUg5TkoM+pDBND/5bEWaIWRuvfRyijMJSPp0tlu7c7jtZuiT3gEzce3oK 53GzmrZAmm5yN637U5IWa0FuNqTm2XpV6N+JYtsNG6HwKSVpXkMQrhTVND0rDs+PNn Cp5KH6QB4qIMzKm1K85DJzHbjIaxX/rYtdVYFsaTNwiIa9D4y96tMYaDPcwd3ejmCG NEvcQh1dDIxvw== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 4177F18005F for ; Fri, 28 Jun 2024 18:41:03 +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-pl1-f181.google.com (mail-pl1-f181.google.com [209.85.214.181]) (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 ; Fri, 28 Jun 2024 18:41:02 +0000 (UTC) Received: by mail-pl1-f181.google.com with SMTP id d9443c01a7336-1fa07e4f44eso5925825ad.2 for ; Fri, 28 Jun 2024 11:39:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719599983; x=1720204783; 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=W/n1q/bCdBJUNV3cO1UsJZVBcb3nDcAQJ85bq8ogt0s=; b=nDfzCNY01tDBqaUKHkLkq3LvBUhEXcyXZEm0dczZf70Vxgbc66tt224yeZ6y4rhczu 9JEwUS+PPbnOPqNf8PfiwiZXu8541iC3sCWer4x/RVhNV0bcztmNAbuVTkybYSktZov0 4opArGv+luIoI11fg5Hzzodi6eROK4yW777QETAE4aH/njbuF4Mnj6cej7sdBmvWh/Z1 ID4zcpD4CvQPyfXp9n9OzNfroYq8UBZDv3cV2rgOi6+bf/SiSAygaQN+Elp6zc3HAeQV DKRpEOBIrT/OIoI6YwBMfZXRIZnlh+aJ6hoUnOTqsoWcF7TxScz/KExqas5LnwdXE4AH X41g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719599983; x=1720204783; 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=W/n1q/bCdBJUNV3cO1UsJZVBcb3nDcAQJ85bq8ogt0s=; b=RiokA/HFWMJD9u878mMIeNeYUprrGZGjkEXx2fP68lrgdjMVA+0hWxB55NLDB0dhXF OYlTCqGd+aIRRCvUmsQG/xlS2Fl7PqXmiZAXkHpQKAJzg2WhVuhuvtO6DIhaTdhR+Znf wbQUU1rxNeZllKjxVm133Ja6IpnIELy+mqXhxDUMEx1HpbkgKVIwmIhnq6y6N7Ix2LG7 AwNUePYW0Gt0LXphf+naswhzwJija52nMuwsq3f5Yovqay3WFnhZ85NkqlSJllA0rL2L rseCobpJY2t40uf/fROAntF2cmmZb6ZsrsosG/p5DAjYzeyl05TlsnamdSiwd1Jor4vN H/4Q== X-Gm-Message-State: AOJu0YxYKFseVqLMSgVZJVQPNvVuaskEHMO4sWmF+t2al308Ol/HnQov r6JK8I636R62urDy2HWfB1xULHEfSmpVDrvI/0ETqut3gyVB/P9eDxO32quCp7HPRSdplpXTF9V lKjO5MlgMRhkfBgzWvY/heGFdT66d+w== X-Google-Smtp-Source: AGHT+IFR694dNC0Ve59sGt+7RjaVumhaLd/iNrZ/Y7x+WsCjSU6c+mUERamqrcIwQ8y8L01+AUcIPNfIQbHsBfwZIDI= X-Received: by 2002:a17:902:d509:b0:1f7:c56:58a3 with SMTP id d9443c01a7336-1fa23dce430mr190065905ad.26.1719599982627; Fri, 28 Jun 2024 11:39:42 -0700 (PDT) Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net MIME-Version: 1.0 References: In-Reply-To: Date: Fri, 28 Jun 2024 11:39:30 -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="0000000000001ed346061bf79290" From: jordan.ledoux@gmail.com (Jordan LeDoux) --0000000000001ed346061bf79290 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Fri, Jun 28, 2024 at 10:47=E2=80=AFAM Rob Landers wr= ote: > Hello internals, > > I'd like to introduce a new RFC: > https://wiki.php.net/rfc/operator_overrides_lite which extends the GMP > extension to support a limited set of operator overriding to developers. > It's designed to be limited and relatively simple, while still being quit= e > powerful. It would only be available if you have the GMP extension > installed and enabled, but would allow for creating powerful unit librari= es > (such as representing money, duration, etc). > > I'm very interested in your feedback! > > This was initiated from a discussion in another thread: > https://externals.io/message/123872 > > Thanks for your time, > > Rob Landers > You probably have not actually looked at implementing this yet, so let me give you some advice: 1. You probably are not yet aware that operands get reordered, or their ordering is not guaranteed, when a comparison occurs. This is because there is no op code (currently) for Greater Than or Greater Than Or Equal. Instead the comparison is reordered so that the operands are swapped and a Less Than or a Less Than Or Equal is performed. This is perfectly acceptable until you need to determine whether the left or right operand's function needs to be called, such as with objects. 2. The fact that the signature uses `mixed` for the typing removes a lot of the safety features the previous RFC had, and makes a lot of the concerns that stopped that RFC worse. In PHP currently, an object used with any non-comparison operand results in a TypeError. In the previous proposal, this behavior was preserved *even for objects which implement overloads* unless they specifically listed the type as accepted in the overload definition. What this did is ensure that anything OTHER than a TypeError guaranteed the developer that they were dealing with an operator overload that they could go inspect. 3. The private/protected distinction is fairly meaningless for the functions that implement overloads, because the privacy of the function is ignored completely when it is executed to evaluate an operator. 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. 5. Your voting choices actually constitute something that is not allowed for RFCs. A 'yes' vote allows operator overloads for GMP, a 'no' vote changes GMP to `final`. There is no option here to leave PHP as it currently is, which is what a 'no' vote should mean. 6. The `comparable` function you propose doesn't actually have an operator 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. There's probably more, but this is a start for you to make some improvements and changes. However, I had to warn you before you put in too much effort that I am fairly certain this RFC has very nearly zero chance of passing. Jordan --0000000000001ed346061bf79290 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable


=
On Fri, Jun 28, 2024 at 10:47=E2=80= =AFAM Rob Landers <rob@bottled.codes> wrote:
Hello internals,

I'd like t= o introduce a new RFC:=C2=A0https://wiki.ph= p.net/rfc/operator_overrides_lite=C2=A0which extends the GMP extension = to support a limited set of operator overriding to developers. It's des= igned to be limited and relatively simple, while still being quite powerful= . It would only be available if you have the GMP extension installed and en= abled, but would allow for creating powerful unit libraries (such as repres= enting money, duration, etc).

I'm very int= erested in your feedback!

This was initiated f= rom a discussion in another thread:=C2=A0https://externa= ls.io/message/123872

Thanks for your time,=

Rob Landers

You probably have not actually looked at implementing = this yet, so let me give you some advice:

1. You p= robably are not yet aware that operands get reordered, or their ordering is= not guaranteed, when a comparison occurs. This is because there is no op c= ode (currently) for Greater Than or Greater Than Or Equal. Instead the comp= arison is reordered so that the operands are swapped and a Less Than or a L= ess Than Or Equal is performed. This is perfectly acceptable until you need= to determine whether the left or right operand's function needs to be = called, such as with objects.
2. The fact that the signature uses= `mixed` for the typing removes a lot of the safety features the previous R= FC had, and makes a lot of the concerns that stopped that RFC worse. In PHP= currently, an object used with any non-comparison operand results in a Typ= eError. In the previous proposal, this behavior was preserved *even for obj= ects which implement overloads* unless they specifically listed the type as= accepted in the overload definition. What this did is ensure that anything= OTHER than a TypeError guaranteed the developer that they were dealing wit= h an operator overload that they could go inspect.
3. The private= /protected distinction is fairly meaningless for the functions that impleme= nt overloads, because the privacy of the function is ignored completely whe= n it is executed to evaluate an operator.
4. The `static` distinc= tion is also fairly meaningless, as in PHP there is no situation possible w= here an operator overload can occur WITHOUT it operating on objects themsel= ves.
5. Your voting choices actually constitute something that is= not allowed for RFCs. A 'yes' vote allows operator overloads for G= MP, a 'no' vote changes GMP to `final`. There is no option here to = leave PHP as it currently is, which is what a 'no' vote should mean= .
6. The `comparable` function you propose doesn't actually h= ave an operator 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 insuffi= cient as a return type for that.

There's proba= bly more, but this is a start for you to make some improvements and changes= . However, I had to warn you before you put in too much effort that I am fa= irly certain this RFC has very nearly zero chance of passing.
Jordan
--0000000000001ed346061bf79290--