Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:123918 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 480221A009C for ; Thu, 27 Jun 2024 04:07:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1719461344; bh=jRfGYlAUnPm2hIhRzbUbZaxrcaSD/+p6RYs3Obk8pEY=; h=From:Subject:Date:In-Reply-To:Cc:To:References:From; b=Lmnr4qXjOO62Yo5wPpvwK1vgZ1M2ZNRy8aSJrJ9AuvqjFV9B+kT+ke5pwL6SYhcD5 t1B3F/vII6DuaCVj56AISFMmd3LCmgwJOPQ76DS6INHvQ5LdxgW++2gn1DAcuVa+VX 87glsP2Y2YlQJzt6yjJrR/5X/vfeFF2gkPxqg76Sg6JGR9Bd3yYcJP/1RMyRrr6W48 eoMVsMd68oFzQq2ipfYtGyVLYDxYteuLauSM4WsNstM2GkmrtZTTe35Ztf/ROCxqW5 Tjh0G6wS5SKaFqCkopZRO7hibyZ2Hjlu2IODcl+CY0UVk6Xta3/hJboRM2S1JspmxP Znxps1Z/Dz/hw== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id BA387180CCC for ; Thu, 27 Jun 2024 04:09:02 +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,HTML_MESSAGE, 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 ; Thu, 27 Jun 2024 04:09:01 +0000 (UTC) Received: from smtpclient.apple (unknown [117.55.37.250]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.sakiot.com (Postfix) with ESMTPSA id 7B2F8401FB; Thu, 27 Jun 2024 13:07:39 +0900 (JST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=sakiot.com; s=default; t=1719461259; bh=jRfGYlAUnPm2hIhRzbUbZaxrcaSD/+p6RYs3Obk8pEY=; h=From:Subject:Date:In-Reply-To:Cc:To:References:From; b=QYTTEmfEmIXZ4IVdnidLOjlNu1OWwe0AOU3+RoFt/xaMP1hMZJdOKu+PKCzMSnLWd 1IDIwJo0mU0ns8PK2UCE4EtcqZiZomp/CUr39rIAjRTy3p4KxyzbJSEuwd64lMWQjd 94aBvOsR4Er9Gj0QDN6EQ5lQioCYQi9qTH84KsIs= Message-ID: <64BF2EC8-6B0E-4F5E-95C2-F5DE9B71D141@sakiot.com> Content-Type: multipart/alternative; boundary="Apple-Mail=_607D5E83-88A3-4C6E-AAF8-5620FFF56D47" Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3774.600.62\)) Subject: Re: [PHP-DEV] Overriding GMP objects Date: Thu, 27 Jun 2024 13:07:27 +0900 In-Reply-To: Cc: Rob Landers , internals@lists.php.net To: "Gina P. Banyard" References: <930741fa-eb10-44c6-acbf-34ec9823f8f3@app.fastmail.com> X-Mailer: Apple Mail (2.3774.600.62) From: saki@sakiot.com (Saki Takamachi) --Apple-Mail=_607D5E83-88A3-4C6E-AAF8-5620FFF56D47 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii Hi, > On Wednesday, 26 June 2024 at 18:24, Rob Landers = wrote: >> Hello internals, >>=20 >> I've had this little library for a while = (https://github.com/withinboredom/time), mostly as a place to experiment = with the quirks of PHP and take it in weird places. Anyway, I've been = experimenting with "strongly typed time" in attributes for a while now. = At this point, it's a little weird but doable to use something like = this: >>=20 >> #[MyAttribute(units: StandardSecond, amount: 5)] >>=20 >> ... which is less than ideal. What I would really like is this: >>=20 >> #[MyAttribute(5 * StandardSecond)] >>=20 >> PHP doesn't support operator overloading, which, from the last RFC = attempt, probably won't for quite a long time. Thus, I started = experimenting with extending the \GMP class, which is perfectly allowed = since it isn't final. For those that don't know, GMP implements operator = overloading such that a GMP number times an int results in a new GMP = number. >>=20 >> Surprisingly, I can get this to work, but I end up with a GMP number = -- with the right value -- but not the right type. Hence this email. In = essence, I am attempting to "back-door" my way into having operator = overloading. >>=20 >> I would like to add static protected methods to the GMP class that = are called for operations. In the event all objects are base-GMP = objects, no behavior will change. >=20 > No, GMP not being final was a mistake, mainly due to it the first = conversion from resources to opaque objects. > I was intending on making the class final via an RFC because no one = extends it, as it is pointless (checked also on private codebases via = Exakat). > AND This whole back-door idea was explicitly shut down in the BCNumber = RFC that got accepted for 8.4. >=20 > I do not want a random extension being abused for this purpose. > If you want to add operator overloading by that way you can do = something very simple, which is create a new extension which has a class = with all the relevant method that overloads the do_operator to call the = relevant methods on the class. > You've got your back-door without poluting the problem space of an = unrelated extension which is not even required to be installed. >=20 >> - should we revisit operator overloading instead of me hacking my way = into it? >=20 > Yes. >=20 >> - should we revisit "constant expressions" in attributes >=20 >=20 > I do not see how this relates to the problem space if we have the = above or you use a new dedicated extension for this. >=20 > Best regards, >=20 > Gina P. Banyard I agree with Gina. Being able to change the class of a computed result = of an inherited child class causes several problems. The points raised in the `BCMath\Number` discussion can be summarized as = follows. - If it is possible to perform calculations on parent Class and child = Class, what should the resulting class be? - Multiplying the distance class and the speed class should give you the = time class. - Similarly, multiplying two distance classes together should yield an = area class. - If only child classes have a property that should be specified in the = constructor, how do you determine the value of this property in the = result class? Perhaps it is possible to determine the value of the = property, but in that case the commutativity of the computation should = be lost. These problems cannot be solved without significant complexity. And = there is a possibility that it cannot be resolved in the first place. Regards, Saki --Apple-Mail=_607D5E83-88A3-4C6E-AAF8-5620FFF56D47 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=us-ascii Hi,

On Wednesday, 26 June = 2024 at 18:24, Rob Landers <rob@bottled.codes> wrote:
Hello internals,

I've had = this little library for a while (https://github.com/withinboredom/time), = mostly as a place to experiment with the quirks of PHP and take it = in weird places. Anyway, I've been experimenting with "strongly typed = time" in attributes for a while now. At this point, it's a little weird = but doable to use something like = this:

#[MyAttribute(units: = StandardSecond, amount: 5)]

... = which is less than ideal. What I would really like is = this:

#[MyAttribute(5 * = StandardSecond)]

PHP doesn't support = operator overloading, which, from the last RFC attempt, probably won't = for quite a long time. Thus, I started experimenting with extending the = \GMP class, which is perfectly allowed since it isn't final. For those = that don't know, GMP implements operator overloading such that a GMP = number times an int results in a new GMP = number.

Surprisingly, I can get this to = work, but I end up with a GMP number -- with the right value -- but not = the right type. Hence this email. In essence, I am attempting to = "back-door" my way into having operator = overloading.

I would like to add static = protected methods to the GMP class that are called for operations. In = the event all objects are base-GMP objects, no behavior will = change.

No, GMP not being final was a = mistake, mainly due to it the first conversion from resources to opaque = objects.
I was intending on making = the class final via an RFC because no one extends it, as it is pointless = (checked also on private codebases via Exakat).
AND This whole back-door idea was = explicitly shut down in the BCNumber RFC that got accepted for = 8.4.

I do not want a random extension = being abused for this purpose.
If = you want to add operator overloading by that way you can do something = very simple, which is create a new extension which has a class with all = the relevant method that overloads the do_operator to call the relevant = methods on the class.
You've got your = back-door without poluting the problem space of an unrelated extension = which is not even required to be = installed.

- should we revisit operator overloading instead of = me hacking my way into it?

Yes.

- should we revisit = "constant expressions" in attributes

I do not see how = this relates to the problem space if we have the above or you use a new = dedicated extension for this.

Best = regards,

Gina P. = Banyard

I= agree with Gina. Being able to change the class of a computed = result of an inherited child class causes several = problems.

The points raised in the = `BCMath\Number` discussion can be summarized as = follows.

- If it is possible to perform = calculations on parent Class and child Class, what should the resulting = class be?
- Multiplying the distance class and the speed = class should give you the time class.
- Similarly, = multiplying two distance classes together should yield an area = class.
- If only child classes have a property that = should be specified in the constructor, how do you determine the value = of this property in the result class? Perhaps it is possible to = determine the value of the property, but in that case the commutativity = of the computation should be lost.

These = problems cannot be solved without significant complexity. And there is a = possibility that it cannot be resolved in the first = place.

Regards,

Saki

= --Apple-Mail=_607D5E83-88A3-4C6E-AAF8-5620FFF56D47--