Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:124031 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 C21F81ADCD7 for ; Sat, 29 Jun 2024 12:28:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1719664192; bh=00JU0Q6WYRFdmQZCxTVGAzv5bgnAnTRMUjBvQrhv824=; h=From:Subject:Date:References:Cc:In-Reply-To:To:From; b=UD5iRja8GdlWZebkif6tPQGjNCEJ4e3o47RyLnTkmvV3HzMV+hWbDmoiF+Z096kH8 AvXg2bGYuImHbzeZxFkCaArVPL/bvgKyM6VxDbQfjqC/LI/A/dTPL4Oam0DaNFYWho A2YMHb5vZ/9jw4bKAyeFG1hlPQzp/5qpFI5CmCc0yXqevR2SVG6XfNnIOacrQPDR2F +sbrbJAQIuZar+aInagx5mtd5jDXPJjbjUwiE/I2qED7mPowJbTSM2GaZ1QgRoPSrW sCWzCHuhcQsY04HGzwfQHDvvNXLe1ywDik5re227BhzW7rgVQJ1bezPrT8pEshM0W+ OTmSIuLfxK7Gg== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 0B30218005B for ; Sat, 29 Jun 2024 12:29:49 +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.8 required=5.0 tests=BAYES_50,DMARC_PASS, HTML_MESSAGE,MIME_QP_LONG_LINE,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.sakiot.com (mail.sakiot.com [160.16.227.216]) (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 12:29:45 +0000 (UTC) Received: from smtpclient.apple (230.152.159.133.rev.vmobile.jp [133.159.152.230]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by mail.sakiot.com (Postfix) with ESMTPSA id 3B303401EB; Sat, 29 Jun 2024 21:28:24 +0900 (JST) Content-Type: multipart/alternative; boundary=Apple-Mail-9142B524-1DB0-4719-B8FD-B1F68C092B79 Content-Transfer-Encoding: 7bit Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net Mime-Version: 1.0 (1.0) Subject: Re: [PHP-DEV] [RFC] Operator Overrides -- Lite Edition Date: Sat, 29 Jun 2024 21:28:10 +0900 Message-ID: <89C9AC15-1456-46AE-9183-DFDA7D0D381D@sakiot.com> References: <90dd3eb6-c7be-4951-a6b6-fd3785ed92e5@app.fastmail.com> Cc: Jordan LeDoux , internals@lists.php.net In-Reply-To: <90dd3eb6-c7be-4951-a6b6-fd3785ed92e5@app.fastmail.com> To: Rob Landers X-Mailer: iPhone Mail (21F90) From: saki@sakiot.com (Saki Takamachi) --Apple-Mail-9142B524-1DB0-4719-B8FD-B1F68C092B79 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Hi, > On Sat, Jun 29, 2024, at 02:13, Jordan LeDoux wrote: >>> 4. The `static` distinction is also fairly meaningless, as in PHP there i= s no situation possible where an operator overload can occur WITHOUT it oper= ating on objects themselves. >>=20 >> 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 m= erely represent the value. >>=20 >> A GMP object instance that does not know its value? What are you even tal= king about? Can you show me some code explaining what you mean? I had litera= lly months of this argument for the operator overloads RFC, and studied the o= verload 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. >=20 > A few minutes ago, I sent an email where I accidentally made the code non-= static, and I think I see the merit in what you are saying. It felt so natur= al to use $this that I didn't even realize I was doing it wrong. >=20 > So, looking at your RFC and mine, I think this can be improved. >=20 > What would you suggest it look like and then we can work backwards from th= ere? Here are my thoughts on your code. In theory, inheriting from this "improved GMP class" would allow overloading= of computational operators. In effect, this acts like a "calcable interface", with the constructor passi= ng in meaningless values =E2=80=8B=E2=80=8Bto the parent constructor and the= add method allowing the user to freely modify the return value. This means that virtually any userland class can use the operator overloadin= g feature via a "hack". This approach is completely wrong. Rather than proposing this as is, it woul= d be more constructive to propose support for operator overloading. Regards, Saki= --Apple-Mail-9142B524-1DB0-4719-B8FD-B1F68C092B79 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable
Hi,=

On Sat, Jun 29, 2024, a= t 02:13, Jordan LeDoux wrote:
= 4. The `static` distinction is also fairly meaningless, as in PHP there is n= o situation possible where an operator overload can occur WITHOUT it operati= ng on objects themselves.

<= div>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 code explaining what you mean? I had li= terally months of this argument for the operator overloads RFC, and studied t= he overload implementations in six other languages as part of writing that R= FC, I feel like I understand this topic fairly well. But I do not understand= what you are saying here.

=
A few minutes ago, I sent an email where I accidentally made the code n= on-static, and I think I see the merit in what you are saying. It felt so na= tural to use $this that I didn't even realize I was doing it wrong.

So, looking at your RFC and mine, I think this can be i= mproved.

What would you suggest it look like an= d then we can work backwards from there?

He= re are my thoughts on your code.

In theory, inherit= ing from this "improved GMP class" would allow overloading of computational o= perators.

In effect, this acts like a "calcable int= erface", with the constructor passing in meaningless values =E2=80=8B=E2=80=8B= to the parent constructor and the add method allowing the user to freely mod= ify the return value.

This means that virtually any= userland class can use the operator overloading feature via a "hack".
=

This approach is completely wrong. Rather than proposing= this as is, it would be more constructive to propose support for operator o= verloading.

Regards,

Saki<= /div>= --Apple-Mail-9142B524-1DB0-4719-B8FD-B1F68C092B79--