Newsgroups: php.internals,php.internals Path: news.php.net Xref: news.php.net php.internals:123873 php.internals:123874 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 F15E71A009C for ; Wed, 26 Jun 2024 17:57:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1719424734; bh=mZY5d1jgkRFEAJNIHdECsb6zEr1DLL3PnIKzJ8ILQ0A=; h=From:Subject:Date:In-Reply-To:Cc:To:References:From; b=I4fu0ckKTXy1TImsEpYXJBHo1l9NV8I7JtxUvnqOTQrbgu5jG43vz24UK1iNbRXhY OiDzCj2wf6MCwobZHkYOlbbkmifFWYKfo0Eg3yPPJSr8tSIndocwLlTEoHE2T5ekan oPGP6C+raRHagmTcwyjTo+rN3tQalTnbGYMgR67EFb86GOMhJXlrhLOXu6aK2FcRFG v6AZo4reITl/bdBXF2QphnPt7n4YQpKfsf/V0RMLvNv11VdqxDaDZV1UD1z8gp2ksr LEKtc8P4PHphuJLUrQKS5QFJ+dBAf7GudN+Pkf6pkzgUG5+vsIr9W8zM2VxI/iUOGA Cdl9CR/uG0Rzg== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 62820180072 for ; Wed, 26 Jun 2024 17:58:53 +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_MISSING,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-il1-f178.google.com (mail-il1-f178.google.com [209.85.166.178]) (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 17:58:52 +0000 (UTC) Received: by mail-il1-f178.google.com with SMTP id e9e14a558f8ab-376208fbe7bso29705755ab.3 for ; Wed, 26 Jun 2024 10:57:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=miles.systems; s=google; t=1719424654; x=1720029454; darn=lists.php.net; h=references:to:cc:in-reply-to:date:subject:mime-version:message-id :from:from:to:cc:subject:date:message-id:reply-to; bh=n1GBDU4YJrHRXDWfnYIRPqBA0hBeNXSZ+aeKvncTc7o=; b=dPSTYpL6dXfqbRgjoWc4AhTa2l6lg7dRW7lLCLFRZ4Y32rGPrDcgCRlB+jzyKZTpow hF8JDE7UMJqHmZpZvqPr1q7qmb1fOoqobFrazx+L81RP8zMCMzRS82p4wyOejNB8ukiW lWryDSsI8/ZPVFOvtLYYXR9HIKG0ypedsK31YSWamiw294JbfEo1uHaxDlpL50QDS0NL 9SW+PaHfvV33NxaYKnRctr9k5wLFlkNr63TMIIxxu+5kYxWGKYEJftz12H2sk9wjAVfK UDTGmBoSEfA57A8v9LD1fDaZajhhUhUJlFPSLE3/1IgjSXx3WcEGiu2CzuihMz5pXAL9 PRLQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719424654; x=1720029454; h=references:to:cc:in-reply-to:date:subject:mime-version:message-id :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=n1GBDU4YJrHRXDWfnYIRPqBA0hBeNXSZ+aeKvncTc7o=; b=dJ9MdCneH3VdLJ8+ThkUVRrI1W2wdh/4cxN4vXTksU43Tel1ZcrG9prR7WhCmMxIqU LUROSV20YFw9LbzJd8sCimzTa7FEr72jlBjkE2aEY6QK+sBntIgnoOVbvUBnbv2x0ES2 PxR34sA1568cQqgNlEDhL6ncRoJN5h4vR+Xdd+OWagQbRBT7NmtVvpzvqu3eX0kJK1u/ lOhFEqFBkTtJ0+BbQwaWlC8fXaLJrokhqazj0alLS8lvhMz6jglvpYkDivmIS82DuG5p bzV+2aDsHfi5mq/Ph2zH9cBqTT5VEGU/Q4xbJOo/GVLUHDQWIG9NBm8ZolkhqPF29D3F +0gQ== X-Gm-Message-State: AOJu0YwljaQiOjFPiZD0SzJ1Yrli1wcTXlLPOylGhO4PnqfH5OwRRqtj Ma/g4GQx9Kf9mgHGC3ciNPMY52Mt3SY+GDoloLTbpZw/EfLX5s1a3QxO4oTfge5o4Ptdkliyy4u x X-Google-Smtp-Source: AGHT+IGwaM6qsPuL2LNWOBQsuWEbwlng1DXe6mdRHgKiYd+0TH24x8n8Ln5egsj1p6xZfMDac2FXLA== X-Received: by 2002:a05:6e02:2145:b0:376:38f9:3ea1 with SMTP id e9e14a558f8ab-3763df47804mr166479825ab.4.1719424654127; Wed, 26 Jun 2024 10:57:34 -0700 (PDT) Received: from smtpclient.apple ([2601:283:4600:6770:1058:1c9c:6c8b:173a]) by smtp.gmail.com with ESMTPSA id 8926c6da1cb9f-4b9d12487ddsm3314774173.157.2024.06.26.10.57.33 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 26 Jun 2024 10:57:33 -0700 (PDT) Message-ID: <0F7B09EC-C38E-4B49-9137-1FB3EA5231AC@miles.systems> Content-Type: multipart/alternative; boundary="Apple-Mail=_B80798C1-7878-4DF8-A259-B417E21793A6" 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] [Early Feedback] Pattern matching Date: Wed, 26 Jun 2024 11:57:22 -0600 In-Reply-To: Cc: php internals To: Larry Garfield References: <2a6b92eb-d5e9-4a1a-9548-a068ac42ebd2@app.fastmail.com> X-Mailer: Apple Mail (2.3774.600.62) From: richard@miles.systems (Richard Miles) --Apple-Mail=_B80798C1-7878-4DF8-A259-B417E21793A6 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 =E2=80=9CArray-application will also be pushed to future-scope=E2=80=9D 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 = thinking about what it would look like for strictly typed arrays in PHP = for a while now. I think a custom implantation like SqlObjectStorage or = SplFixedArray could help performance since we now have a fixed list and = no need for a hash table, and it may solve some complexity in = implementation. This is slightly off-topic, but if anyone is interested = in working on a typed arrays initiative, please contact me directly.=20 That said, I agree with Robert Landers, who wrote the following: There's no need 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. ______ I think there is a need to ensure a key does not exist even if we=E2=80=99= re 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 Best, Richard Miles > On Jun 24, 2024, at 5:31=E2=80=AFPM, Larry Garfield = wrote: >=20 > On Thu, Jun 20, 2024, at 5:38 PM, Larry Garfield wrote: >=20 >> To that end, we're looking for *very high level* feedback on this = RFC: >>=20 >> https://wiki.php.net/rfc/pattern-matching >=20 > Hi folks. Thank you to those who have offered feedback so far. Based = on the discussion, here's what we're thinking of doing (still subject to = change, of course): >=20 > * We're going to move `as` to future-scope. There's enough weirdness = around it that is independent of pattern matching itself that it will = likely require its own discussion and RFC, and may or may not involve = full pattern support. >=20 > * Similarly, we're going to hold off on the weak-mode flag. It sounds = like the language needs to do more to fix the definition of "weak mode" = before it's really viable. :-( On the plus side, if the type system = itself ever adds support for a "coercion permitted" flag, patterns = should inherit that naturally, I think. >=20 > * Array-application will also be pushed to future-scope. Again, = there's enough type-system tie in here that is tangential to patterns = that we'll pick that fight later. >=20 > * Ilija and I have discussed regex patterns a bit further, and it = sounds like they=E2=80=99re going to be rather complicated to implement. = Even assuming we agree on the syntax for it, it would be a substantial = amount of code to support. (It=E2=80=99s not like types or literals or = range where we can just drop something pre-existing into a new = function.) So we=E2=80=99re going to hold off on this one for now, = though it does seem like a high-priority follow-up for the future. = (Which doesn=E2=80=99t have to be us!) >=20 > So let's not discuss the above items further at this point. >=20 > * I'm going to do some additional research into other languages to see = how they handle binding vs using variables from scope, and what syntax = markers they use and where. Once we have a better sense of what is out = there and is known to work, we can make a more informed plan for what we = should do in PHP. (Whether using a variable from scope in the pattern = is part of the initial RFC is still an open question, but we do need to = design it alongside the capture part to ensure they don't conflict.) = Stay tuned on this front. >=20 > * We've removed the dedicated wildcard pattern, as it's equivalent to = `mixed`. If there's interest, we're open to having a secondary vote to = bring it back as a short-hand pattern. It's trivial to implement and we = don't have strong feelings either way. >=20 > * There's not been much discussion of range patterns. Anyone want to = weigh in on those? >=20 > * The placement of `is` on `match()` is still an open question. >=20 > * No one has really weighed in on nested patterns for captured = variables. Any thoughts there? >=20 > * I=E2=80=99ve seen a suggestion for capturing the =E2=80=9Crest=E2=80=9D= of an array when using =E2=80=A6 That=E2=80=99s an interesting idea, = and we=E2=80=99ll explore it, though it looks like it may have some = interesting implications that push it to future scope. It feels like a = nice-to-have. >=20 > Thanks all. >=20 > --Larry Garfield --Apple-Mail=_B80798C1-7878-4DF8-A259-B417E21793A6 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=utf-8 =E2=80=9CArray-application will also be pushed to = future-scope=E2=80=9D


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 thinking about what = it would look like for strictly typed arrays in PHP for a while now. I = think a custom implantation like SqlObjectStorage or SplFixedArray could = help performance since we now have a fixed list and no need for a hash = table, and it may solve some complexity in implementation. This is = slightly off-topic, but if anyone is interested in working on a typed = arrays initiative, please contact me = directly. 


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

There's no need 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.
______

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. 

Best,

Richard = Miles


On Jun 24, 2024, at 5:31=E2=80=AFP= M, Larry Garfield <larry@garfieldtech.com> wrote:

On Thu, Jun 20, 2024, at = 5:38 PM, Larry Garfield wrote:

To that = end, we're looking for *very high level* feedback on this = RFC:

https://wiki.php.net/rfc/pattern-matching

= Hi folks.  Thank you to those who have offered feedback so far. =  Based on the discussion, here's what we're thinking of doing = (still subject to change, of course):

* We're going to move `as` = to future-scope.  There's enough weirdness around it that is = independent of pattern matching itself that it will likely require its = own discussion and RFC, and may or may not involve full pattern = support.

* Similarly, we're going to hold off on the weak-mode = flag.  It sounds like the language needs to do more to fix the = definition of "weak mode" before it's really viable. :-(  On the = plus side, if the type system itself ever adds support for a "coercion = permitted" flag, patterns should inherit that naturally, I = think.

* Array-application will also be pushed to future-scope. =  Again, there's enough type-system tie in here that is tangential = to patterns that we'll pick that fight later.

* Ilija and I have = discussed regex patterns a bit further, and it sounds like they=E2=80=99re= going to be rather complicated to implement.  Even assuming we = agree on the syntax for it, it would be a substantial amount of code to = support.  (It=E2=80=99s not like types or literals or range where = we can just drop something pre-existing into a new function.)  So = we=E2=80=99re going to hold off on this one for now, though it does seem = like a high-priority follow-up for the future.  (Which doesn=E2=80=99= t have to be us!)

So let's not discuss the above items further at = this point.

* I'm going to do some additional research into other = languages to see how they handle binding vs using variables from scope, = and what syntax markers they use and where.  Once we have a better = sense of what is out there and is known to work, we can make a more = informed plan for what we should do in PHP.  (Whether using a = variable from scope in the pattern is part of the initial RFC is still = an open question, but we do need to design it alongside the capture part = to ensure they don't conflict.)  Stay tuned on this front.

* = We've removed the dedicated wildcard pattern, as it's equivalent to = `mixed`.  If there's interest, we're open to having a secondary = vote to bring it back as a short-hand pattern.  It's trivial to = implement and we don't have strong feelings either way.

* There's = not been much discussion of range patterns.  Anyone want to weigh = in on those?

* The placement of `is` on `match()` is still an = open question.

* No one has really weighed in on nested patterns = for captured variables.  Any thoughts there?

* I=E2=80=99ve = seen a suggestion for capturing the =E2=80=9Crest=E2=80=9D of an array = when using =E2=80=A6  That=E2=80=99s an interesting idea, and = we=E2=80=99ll explore it, though it looks like it may have some = interesting implications that push it to future scope.  It feels = like a nice-to-have.

Thanks all.

--Larry = Garfield

= --Apple-Mail=_B80798C1-7878-4DF8-A259-B417E21793A6--