Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:123966 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 B4C261A009C for ; Thu, 27 Jun 2024 21:07:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1719522499; bh=1xF3aOkY3wdRH3fTtkcnIvD2A1bG/1jTbgFLSSWgl0Q=; h=In-Reply-To:References:Date:From:To:Cc:Subject:From; b=QLx3kY/w+V2rR4L1ww4r+NCErGDSse7jN4ihOFvWjvGyReYuq+/c1PT0RCExkuVyw nOCuSUBVLmyalx/+x2W3NUzQhlOMegIKBONwnlylxhOg91aM3Km9AZZFpSxnAWAksG sHV/Bnj+PVLaynzvy3BfQ2KoqXxZpte+VAjUdLkpNhJia5vBD3LN+Jny4FyHobu1K9 wjVxXV6y301USiDCBfRBryqvj4V6ZC5lg5DE42pPxD9cCE7g7x3n6fP8gGTubJ+521 8AtmFwL1PpwNLVm4UyJu7+sDtaUMfR2q9NKz+5N/buu19LTL7f9MGwDzQPJPpXj3GL 5kmpGh/X+iemQ== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id CC78F181728 for ; Thu, 27 Jun 2024 21:08:17 +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.1 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_MISSING,HTML_MESSAGE, RCVD_IN_DNSWL_LOW,SPF_HELO_PASS,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 wfout1-smtp.messagingengine.com (wfout1-smtp.messagingengine.com [64.147.123.144]) (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:08:15 +0000 (UTC) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailfout.west.internal (Postfix) with ESMTP id 656CB1C000B6; Thu, 27 Jun 2024 17:06:56 -0400 (EDT) Received: from imap49 ([10.202.2.99]) by compute1.internal (MEProxy); Thu, 27 Jun 2024 17:06:56 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bottled.codes; h=cc:cc:content-type:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to; s=fm3; t=1719522416; x= 1719608816; bh=1xF3aOkY3wdRH3fTtkcnIvD2A1bG/1jTbgFLSSWgl0Q=; b=t FQNuqf0HLp/Lf3n05Jl0yvepuy2yGAHms7T4MMONuXuJoOTj2y7qFj79y40uTLd1 axfGht83/Yo4KOF0RUUF+rPOvD9ONmEX+cqfbfm+m2N2oL4GzB96uIZp5yPzj74/ KX25dLzqZVGe3bqbchjsbvFxNNbYsNaw6X5I5sRuKkWdFe9Fj9je5uSTOr3HzDel egT2BUr5cHCsC35yHr9bV43k75+dTvLEhcnKlCQjGNCOvVi8KkRCtdgwaLGjFqn7 Bhwbl1b8grLVVMr/XwM5TzxFGw8ChNsQm4i6G6uHaVBKdQwJxpSWeWYKgcPOjTta 9+Ix1UG1+R0i6GHJU0Ofg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm2; t=1719522416; x=1719608816; bh=1xF3aOkY3wdRH3fTtkcnIvD2A1bG /1jTbgFLSSWgl0Q=; b=dfqM2+i2GCF7PCUuadW79NXWEwIrQxuPh3xcnFqWgVLZ J6p85ESh/KskyInEkH2T07SCvd1DtZRnVivVk9KGRME6rLsgLIz8KRVSrwQWkohY 4F+/Frn7C6gbd4dt4dBQhiOTzTBlzbzdQt15qH98ACo5gFsvJ1VzSQH9a98R84Ti oAdEerAAWqrFACK+ks1ZGN5d5UxqYAy+4c4mEXF0gJ6opV1rdj/g7zNiV5OK/iiv GQfcas/PClIk707F+/b+zfvSUsh5o/2bNqmUg49AXJRdK0/THaZJ2TP5mNWZaLTa GPvfHmXQTrimlsEXttNqNFYi+tPgPZSu2Pk5RPxicQ== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrtdeggdduheejucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefofgggkfgjfhffhffvvefutgesrg dtreerreerjeenucfhrhhomhepfdftohgsucfnrghnuggvrhhsfdcuoehrohgssegsohht thhlvggurdgtohguvghsqeenucggtffrrghtthgvrhhnpedvkeeltefhvdffudevuedttd dutdeltefguefgjeefheeijedvgeejueeufeevgfenucffohhmrghinhepghhithhhuhgs rdgtohhmnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomh eprhhosgessghothhtlhgvugdrtghouggvsh X-ME-Proxy: Feedback-ID: ifab94697:Fastmail Received: by mailuser.nyi.internal (Postfix, from userid 501) id 9C1CD15A0092; Thu, 27 Jun 2024 17:06:55 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.11.0-alpha0-538-g1508afaa2-fm-20240616.001-g1508afaa Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net MIME-Version: 1.0 Message-ID: <4ac12229-800a-4151-97d0-08d38784fcaf@app.fastmail.com> In-Reply-To: References: <930741fa-eb10-44c6-acbf-34ec9823f8f3@app.fastmail.com> Date: Thu, 27 Jun 2024 23:06:35 +0200 To: "Gina P. Banyard" Cc: internals@lists.php.net Subject: Re: [PHP-DEV] Overriding GMP objects Content-Type: multipart/alternative; boundary=c2156dcc3f6f481ab879f6d813944ae2 From: rob@bottled.codes ("Rob Landers") --c2156dcc3f6f481ab879f6d813944ae2 Content-Type: text/plain;charset=utf-8 Content-Transfer-Encoding: quoted-printable On Thu, Jun 27, 2024, at 05:39, Gina P. Banyard wrote: > On Wednesday, 26 June 2024 at 18:24, Rob Landers w= rote: >> Hello internals, >>=20 >> I've had this little library for a while (https://github.com/withinbo= redom/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 at= tempt, probably won't for quite a long time. Thus, I started experimenti= ng with extending the \GMP class, which is perfectly allowed since it is= n't final. For those that don't know, GMP implements operator overloadin= g 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 over= loading. >>=20 >> I would like to add static protected methods to the GMP class that ar= e 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 conv= ersion from resources to opaque objects. > I was intending on making the class final via an RFC because no one ex= tends it, as it is pointless (checked also on private codebases via Exak= at). > AND This whole back-door idea was explicitly shut down in the BCNumber= RFC 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 st= ill needs fleshing out, but for any kind of units library, it is an amaz= ing accident. I=E2=80=99d argue for keeping it or even embracing it.=20 =E2=80=94 Rob --c2156dcc3f6f481ab879f6d813944ae2 Content-Type: text/html;charset=utf-8 Content-Transfer-Encoding: quoted-printable
On Thu, Jun 27,= 2024, at 05:39, Gina P. Banyard wrote:
On Wedne= sday, 26 June 2024 at 18:24, Rob Landers <rob@bottled.codes> wrote= :
= Hello internals,

I've had this little libra= ry 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 attribute= s for a while now. At this point, it's a little weird but doable to use = something like this:

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

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

#[MyAttribute(5 * StandardSecond)]

PHP doesn't support operator overloadin= g, which, from the last RFC attempt, probably won't for quite a long tim= e. 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 resu= lts in a new GMP number.

Surprisingly, I ca= n get this to work, but I end up with a GMP number -- with the right val= ue -- but not the right type. Hence this email. In essence, I am attempt= ing 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.

Oops, I extended it :p (pun not intended)
=

In all seriousness, I actually find it a little weir= d but the weirdness can be tucked away (check the readme file) for an er= gonomic usage. It still needs fleshing out, but for any kind of units li= brary, it is an amazing accident. I=E2=80=99d argue for keeping it or ev= en embracing it. 

= =E2=80=94 Rob
--c2156dcc3f6f481ab879f6d813944ae2--