Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:123879 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 51B6F1A009C for ; Wed, 26 Jun 2024 18:39:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1719427239; bh=RGNBgCaKMq4vwjFUc+hsqque2i4puWdRk3ieWvCY7R4=; h=In-Reply-To:References:Date:From:To:Subject:From; b=iIeJ6+eonja1sxb34Bd06T/KERUA4Gwqh1NBIPTgtlYMmMymQFGmLwUrN1GCjRBlE iC/VHTI6VVLPREJhoNpD3WFnMHQxyYDJyyJhPkX8QlXcIQ9zsSJ87fUVZ1io83Q6JQ YgGO8CP7HElpce6alcrFkpPgbEZnu6Es7fY8U8OmoiyZab7kgKt0Re7x3W59YrjxZJ 2AvND+UdJKBknJnLOjCiHWJlDpR9P+q4mLBzvsysGrX8TeJSXVaEpLA/tHRKvN0uUa uMC70Cr9iT2YXusOG7oLBJJO250x1tVQ510toZo7hQg3vb7XT/ZJ6QuEZAtF4obirx 2OirXmZsqIe4A== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id A420D180964 for ; Wed, 26 Jun 2024 18:40:38 +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 fhigh8-smtp.messagingengine.com (fhigh8-smtp.messagingengine.com [103.168.172.159]) (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 ; Wed, 26 Jun 2024 18:40:38 +0000 (UTC) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 252791140101 for ; Wed, 26 Jun 2024 14:39:20 -0400 (EDT) Received: from imap49 ([10.202.2.99]) by compute1.internal (MEProxy); Wed, 26 Jun 2024 14:39:20 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bottled.codes; h=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=1719427160; x=1719513560; bh=RGNBgCaKMq 4vwjFUc+hsqque2i4puWdRk3ieWvCY7R4=; b=DEu5Is5yuIIfcvwRrrlzueIpMT wc2zslfVs67DipuL6RbHaLC//G3f9lUT4f5gov1UxMUjlcnS8QYELk1iiKq6dkuJ xC0pnRrontbLpPoPZNVkVhLmDXydBF2R9JmWBvyP20boz0qXTYwdWpnN4jfJcdTt 3ri6mVPuMQNjAMvlzaBebQSZMXFbukjv6dGYm4JkfrpgcCEtIBR1DFU6cFxSYjxC BYhCkSlDhCDBtgSEk6Sor8bOQGQ5fW/YH9gYWYGgmWQQdOEX0d8lfaAPApZ3Pnv1 bIsHqTUEz42s0bW7XPUC5OlbvykWnawv6IQ6xascajcSNvFwnTorHNv1R/1g== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=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=1719427160; x=1719513560; bh=RGNBgCaKMq4vwjFUc+hsqque2i4p uWdRk3ieWvCY7R4=; b=SmddJ0cXOzdEoQZo/Cb2Ds2Q+CV2bGDom/9JFy1Lvayt QjoujH+9YMoxf1PRjODA3nnEI9fJQg3sMoSxQBTvZbtAU2Ohf1JyHLG0A4jVu1l/ nlo2AKVl+04qpWBdNwEE8DhBuWEaQCsjWPeXM7itosyVj/VIwvU4Uq/dVxR2x34G 9lysAfdvr2ewtTLYTshGYuLVTG2cEiphWtl9ibjg2BTfYglmbI++W52s7mQ51dG7 PhjZCkZ6E+pGAod7Ub6KG2WaOU0o5kT4yiSme32VzJzw8+72fqrKhYk9uXbhMAOr EWe3g5+XSrXldovAipP6PcBIiy6xShzaUF3z5FVWVQ== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrtddvgdduvdelucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefofgggkfgjfhffhffvufgtsegrtd erreerreejnecuhfhrohhmpedftfhosgcunfgrnhguvghrshdfuceorhhosgessghothht lhgvugdrtghouggvsheqnecuggftrfgrthhtvghrnhepgfekjeeljeejieeggfejhedvge dtuddvgeelfeegveduleejvefhleekvddvhfegnecuffhomhgrihhnpeifihhthhhinhgs ohhrvgguohhmrdhinhhfohenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmh grihhlfhhrohhmpehrohgssegsohhtthhlvggurdgtohguvghs X-ME-Proxy: Feedback-ID: ifab94697:Fastmail Received: by mailuser.nyi.internal (Postfix, from userid 501) id B8BC315A0093; Wed, 26 Jun 2024 14:39:19 -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: <6c4bb476-7d4a-4eec-b300-c1d2fe17c631@app.fastmail.com> In-Reply-To: <0F7B09EC-C38E-4B49-9137-1FB3EA5231AC@miles.systems> References: <2a6b92eb-d5e9-4a1a-9548-a068ac42ebd2@app.fastmail.com> <0F7B09EC-C38E-4B49-9137-1FB3EA5231AC@miles.systems> Date: Wed, 26 Jun 2024 20:38:57 +0200 To: internals@lists.php.net Subject: Re: [PHP-DEV] [Early Feedback] Pattern matching Content-Type: multipart/alternative; boundary=7a8e5f34f49d4a15b2aa473de39d66ab From: rob@bottled.codes ("Rob Landers") --7a8e5f34f49d4a15b2aa473de39d66ab Content-Type: text/plain;charset=utf-8 Content-Transfer-Encoding: quoted-printable On Wed, Jun 26, 2024, at 19:57, Richard Miles wrote: > =E2=80=9CArray-application will also be pushed to future-scope=E2=80=9D >=20 >=20 > Dang, this is what I was looking forward to the most. Helping set some= precedent on this issue, and this is a solid start. I=E2=80=99ve been t= hinking about what it would look like for strictly typed arrays in PHP f= or a while now. I think a custom implantation like SqlObjectStorage or S= plFixedArray could help performance since we now have a fixed list and n= o need for a hash table, and it may solve some complexity in implementat= ion. This is slightly off-topic, but if anyone is interested in working = on a typed arrays initiative, please contact me directly.=20 Just a good ole' circular buffer would be nice for so many things (fiber= microwork queues, etc) :) That being said, you can abuse arrays to get better (or at least the sam= e) performance of SPL for certain data structures (e.g., priority queues= /heaps: https://withinboredom.info/2022/09/04/algorithms-in-php-priority= -queues-and-heaps/ -- the listing isn't complete or fully working, FWIW)= . Those little arrays have much power, and I love them for some tasks. >=20 > That said, I agree with Robert Landers, who wrote the following: >=20 > There's no need to use `?` to check for existence on a key, so this: >=20 > $arr is ['a' =3D> string, ?'b' =3D> string, ...]; >=20 > should be this: >=20 > $arr is ['a' =3D> string, 'b' =3D> ?string, =E2=80=A6]; >=20 > ______ >=20 > Chuck Adams cleared that up with: > The first means b is an optional key, but if it=E2=80=99s there, can o= nly be a string. The second says b is a required key, but it may be a st= ring or null. If there were a binding involved, that determines the type= of the binding in incompatible ways. > ______ >=20 > I think there is a need to ensure a key does not exist even if we=E2=80= =99re not happy about this syntax, but if not having `$arr is ['a' =3D> = string, 'b' =3D> ?string, =E2=80=A6]` would still make me very happy.=20 The only time I can't think of this being important (whether or not a ke= y exists) is during serialization/deserialization, where you may want to= leave something its default value. In that case, you likely won't know = what the keys are supposed to be in the first place (thus unable to use = them in something like "is" or "as"). In the case that you did, this wou= ld be perfectly reasonable: $keys =3D array_keys($arr) is [ "a", ?"b", ?"c"]; It's still weird-looking, but it tells you that the keys may or may not = exist, and it is consistent with itself. However, what if the array is i= n a different order or missing keys (e.g., ["c", "a"])? You can see how = this gets complicated pretty quickly. If I am getting hung up on $arr['n= on-existent-key'] technically being null, you can imagine how someone el= se -- maybe even me if I thought about it long enough -- would argue tha= t ["a", ?"b", ?"c"] may or may not match ["a", "c"] as the arguments for= either way are pretty strong and the usecases for either way being just= as valuable. It's a good call to punt it for deeper discussion later. >=20 > Best, >=20 > Richard Miles Please remember to bottom-post ;) =E2=80=94 Rob --7a8e5f34f49d4a15b2aa473de39d66ab Content-Type: text/html;charset=utf-8 Content-Transfer-Encoding: quoted-printable
On Wed, Ju= n 26, 2024, at 19:57, Richard Miles wrote:
=E2=80=9CArray-= application will also be pushed to future-scope=E2=80=9D
<= div>

Dang, this is what I was looking forwa= rd to the most. Helping set some precedent on this issue, and this is a = solid start. I=E2=80=99ve been thinking about what it would look like fo= r strictly typed arrays in PHP for a while now. I think a custom implant= ation like SqlObjectStorage or SplFixedArray could help performance sinc= e we now have a fixed list and no need for a hash table, and it may solv= e some complexity in implementation. This is slightly off-topic, but if = anyone is interested in working on a typed arrays initiative, please con= tact me directly. 

= Just a good ole' circular buffer would be nice for so many things (fiber= microwork queues, etc) :)

That being said,= you can abuse arrays to get better (or at least the same) performance o= f SPL for certain data structures (e.g., priority queues/heaps: https://= withinboredom.info/2022/09/04/algorithms-in-php-priority-queues-and-heap= s/ -- the listing isn't complete or fully working, FWIW). Those little a= rrays have much power, and I love them for some tasks.

That said, I agree with Robert Landers, = who wrote the following:

There's no ne= ed to use `?` to check for existence on a key, so this:
$arr is ['a' =3D> string, ?'b' =3D> string, ...];
=

should be this:

$= arr is ['a' =3D> string, 'b' =3D> ?string, =E2=80=A6];

______

Chuck Adams = cleared that up with:
The first means b is an optional key= , but if it=E2=80=99s there, can only be a string. The second says b is = a required key, but it may be a string or null. If there were a binding = involved, that determines the type of the binding in incompatible ways.<= br>
______

I think there is a nee= d to ensure a key does not exist even if we=E2=80=99re not happy about t= his syntax, but if not having `$arr is ['a' =3D> string, 'b' =3D> = ?string, =E2=80=A6]` would still make me very happy. 

The only time I can't think of this b= eing important (whether or not a key exists) is during serialization/des= erialization, where you may want to leave something its default value. I= n that case, you likely won't know what the keys are supposed to be in t= he first place (thus unable to use them in something like "is" or "as").= In the case that you did, this would be perfectly reasonable:
=

$keys =3D array_keys($arr) is [ "a", ?"b", ?"c"];

It's still weird-looking, but it tells you th= at the keys may or may not exist, and it is consistent with itself. Howe= ver, what if the array is in a different order or missing keys (e.g., ["= c", "a"])? You can see how this gets complicated pretty quickly. If I am= getting hung up on $arr['non-existent-key'] technically being null, you= can imagine how someone else -- maybe even me if I thought about it lon= g enough -- would argue that ["a", ?"b", ?"c"] may or may not match ["a"= , "c"] as the arguments for either way are pretty strong and the usecase= s for either way being just as valuable. It's a good call to punt it for= deeper discussion later.


=E2=80=94 R= ob
--7a8e5f34f49d4a15b2aa473de39d66ab--