Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:123968 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 4DCA61A009C for ; Thu, 27 Jun 2024 21:18:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1719523189; bh=gFC5xQgdEwfZEI+vs5DfBogx+VCSAkRyv6Banjc6xS8=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=E1R0HC3fvu8fuvJ3e6PvVVvj+w4BlHiB9ZmxWCjbC7wDo/AN32c7G1g0S8YD12/XH Cx3+Sa7UFxpzRUMyEn8Gj1zjp0ymMHKutsKh9mSlEkAVzjrr+SQA7gUlH1PFLSVelI WI8Da/H9dr2jPVYNkRi4Ie31g2oUOI5MikOEB6ACIHaLIQIa99EzXSyYlHBaMkqnJx oe/l0dtOEDzZN5I1sY4VoH9oFwLmME8qWXrtYtxZ5/MQyqcz9tAjUjbRfeXnPnGk3C kr4gdmof4wSpfSHnGDyeM6MtBC//+gtduJgOEmlSbf8Kh+LQ7j96kuuFGJWUxdjqzU K0SK2VU/j+LNA== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id ECCAB181905 for ; Thu, 27 Jun 2024 21:19:46 +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_H2,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-oi1-f169.google.com (mail-oi1-f169.google.com [209.85.167.169]) (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 21:19:44 +0000 (UTC) Received: by mail-oi1-f169.google.com with SMTP id 5614622812f47-3d5611cdc52so1039516b6e.0 for ; Thu, 27 Jun 2024 14:18:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719523106; x=1720127906; 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=gFC5xQgdEwfZEI+vs5DfBogx+VCSAkRyv6Banjc6xS8=; b=KsSBdvSymutjxD5N39L/tcUwJaKD3F/to7PU6GVjNIFZA9ZPXxTSGlN1O4SDF+XIZk r3toMEZU56WyeV4NxPgkdBCnKwESLmnA3fZVD5KqNGrKQ7U3qzrd1/hoJuA/1OBFDiNN ovyFwEQnAM5ho6gzEUWS4KR85QPd5G+yzebRpG84fQcWeCH+gIzJ9lOVymI4dzXZlnGH WdXXFpuryoH19rUQrrjMSZVe+QoRbEB35I3f/HVNwFFfTspIPupob9EiEXPhgaoTaCOi xFPSE0RXZUcBU4HJfITpPda7gE7LRgc4PKxeUB/5MbOsu2psJ+yAlOOwCD82XkPFcrdB zDaA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719523106; x=1720127906; 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=gFC5xQgdEwfZEI+vs5DfBogx+VCSAkRyv6Banjc6xS8=; b=rfCtXCfX8Rnn01aEjNR/u3WxW0t5mLYHxodyxymOxIxblNQqHK53seCUQI2hXFOa1A goEdUrb6W34nFfr/OQzHPFkEHsQfvL5eLuKfhgTZKVRoW9nxaulwRBuzrtpeH4hKxuy8 KUShDF5vhibHGpwut3/LaOjMp/a4dQmI/v+UgdhbnD1OwiSBbT/iDMhtFREFCB3Ho5WI XhLjSHcL1V3VC7OORGbUP07t0Pbx/o4nUBNMoJodgSuikIo7fG3t5h34DK0ntFAStH16 mCMFZEMRwPSFVhAUxIkNH/GWtoz0nV2y1OHfhgwAZTquBlHGV3TrvUS5y5Dq9+KeNpTn o+LA== X-Forwarded-Encrypted: i=1; AJvYcCWEGmUsSDB4nA7PigY/ZXHY6dSadOk8wH9FkHpfQO3Z/u/YF6xDWMk9hHREtw/zH/FhNvztcVjSYCW41t5IAmLrbdog03h2+A== X-Gm-Message-State: AOJu0Yz4Qxazg0p82jOSxr2e/PG8Vevx0bb6N9KqlaDwIoerxcg8L9P3 R72QdLSGr7bKZ2XTVLBCKIbtCT5xePKKpuGpfFYjiXOQv3aePPDO7WGDdQHwUyT6qrHe1mOCFd2 +NMNlXG5n+w/qmXA5RYFnugto400FBg== X-Google-Smtp-Source: AGHT+IFLL9NNB5Z7wh3+CU/NgMaW2W5qwSkMRZaRW2JE4rpBWToAT5sLnt06DqWKkXDXKTWPR1H2BJBwPk//jE34UBU= X-Received: by 2002:a05:6808:2105:b0:3d5:6754:7ff with SMTP id 5614622812f47-3d567540afdmr3518363b6e.42.1719523105694; Thu, 27 Jun 2024 14:18:25 -0700 (PDT) Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net MIME-Version: 1.0 References: <930741fa-eb10-44c6-acbf-34ec9823f8f3@app.fastmail.com> <4ac12229-800a-4151-97d0-08d38784fcaf@app.fastmail.com> In-Reply-To: <4ac12229-800a-4151-97d0-08d38784fcaf@app.fastmail.com> Date: Thu, 27 Jun 2024 14:18:15 -0700 Message-ID: Subject: Re: [PHP-DEV] Overriding GMP objects To: Rob Landers Cc: "Gina P. Banyard" , internals@lists.php.net Content-Type: multipart/alternative; boundary="000000000000e5ebea061be5ab8a" From: jordan.ledoux@gmail.com (Jordan LeDoux) --000000000000e5ebea061be5ab8a Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Thu, Jun 27, 2024 at 2:14=E2=80=AFPM Rob Landers wro= te: > On Thu, Jun 27, 2024, at 05:39, Gina P. Banyard wrote: > > On Wednesday, 26 June 2024 at 18:24, Rob Landers > 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. A= t > 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 numb= er. > > 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 RF= C > that got accepted for 8.4. > > > Oops, I extended it :p (pun not intended) > > In all seriousness, I actually find it a little weird but the weirdness > can be tucked away (check the readme file) for an ergonomic usage. It sti= ll > needs fleshing out, but for any kind of units library, it is an amazing > accident. I=E2=80=99d argue for keeping it or even embracing it. > > =E2=80=94 Rob > I don't, that's why I pushed to include operator overloads. In fact, one of the libraries I was going to build (and have already partially built) was a units library that automatically handled unit conversions, multiplications, etc. by keeping track of everything in SI base units and providing different value classes for different combinations of SI base units. If you want to look at how I did that, I can email you the repo for that code directly, though I haven't touched it in a LONG time because it's mostly useless without operator overloads. Jordan --000000000000e5ebea061be5ab8a Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable


=
On Thu, Jun 27, 2024 at 2:14=E2=80=AF= PM Rob Landers <rob@bottled.codes> wrote:
<= /u>
On Thu, Jun 27, 2024, at 05:39, Gina P. Banyard wrote:
On Wed= nesday, 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/withi= nboredom/time), mostly as=C2=A0a 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 poin= t, it's a little weird but doable to use something like this:
=

#[MyAttribute(units: StandardSecond, amount: 5)]
<= div>
... which is less than ideal. What I would really like i= s 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 a= llowed since it isn't final. For those that don't know, GMP impleme= nts operator overloading such that a GMP number times an int results in a n= ew GMP number.

Surprisingly, I can get this to= work, but I end up with a GMP number -- with the right value -- but not th= e right type. Hence this email. In essence, I am attempting to "back-d= oor" 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 b= ehavior 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 mak= ing the class final via an RFC because no one extends it, as it is pointles= s (checked also on private codebases via Exakat).
AND This whole back-door idea was explicitly shut down i= n the BCNumber RFC that got accepted for 8.4.
<= div>
Oops, I extended it :p (pun not intended)
=
In all seriousness, I actually find it a little weird but th= e weirdness can be tucked away (check the readme file) for an ergonomic usa= ge. It still needs fleshing out, but for any kind of units library, it is a= n amazing accident. I=E2=80=99d argue for keeping it or even embracing it.= =C2=A0

=E2=80=94 Rob

I don= 't, that's why I pushed to include operator overloads. In fact, one= of the libraries I was going to build (and have already partially built) w= as a units library that automatically handled unit conversions, multiplicat= ions, etc. by keeping track of everything in SI base units and providing di= fferent value classes for different combinations of SI base units.

If you want to look at how I did that, I can email you the= repo for that code directly, though I haven't touched it in a LONG tim= e because it's mostly useless without operator overloads.

Jordan
--000000000000e5ebea061be5ab8a--