Hi Larry,

On 20.06.24 19:38, Larry Garfield wrote:
Hello, peoples.

Ilija and I have been working on and off on an RFC for pattern matching since 
the early work on Enumerations.  A number of people have noticed and said 
they're looking forward to it.

It's definitely not going to make it into 8.4, but we are looking for early feedback on 
scoping the RFC.  In short, there's a whole bunch of possible patterns that could be 
implemented, and some of them we already have, but we want to get a sense of what scope 
the zeitgeist would want in the "initial" RFC, which would be appropriate as 
secondary votes, and which we should explicitly save-for-later.  The goal is to not spend 
time on particular patterns that will be contentious or not pass, and focus effort on 
fleshing out and polishing those that do have a decent consensus.  (And thereby, we hope, 
avoiding an RFC failing because enough people dislike one little part of it.)

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

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

By "very high level," I mean, please, do not sweat specific syntax details right now.  
That's a distraction.  What we're asking right now is "which of these patterns should we spend 
time sweating specific syntax details on in the coming weeks/months?"  There will be ample 
time for detail bikeshedding later, and we've identified a couple of areas where we know for 
certain further syntax development will be needed because we both hate the current syntax. :-)

If you want to just read the Overview section for a survey of the possible 
patterns and our current recommendations, you likely don't need to read the 
rest of the RFC at this point.  You can if you want, but again, please stay 
high-level.  Our goal at the moment is to get enough feedback to organize the 
different options into three groups:

1. Part of the RFC.
2. Secondary votes in the RFC.
3. Future Scope.

So we know where to focus our efforts to bring it to a proper discussion.

Thank you all for your participation.

Is is already a really nice RFC, even if not finished yet. Also haven't fully read it yet.
Thank you for all your work and time put into it!

I do have some questions:

* For the generics-like pattern I do agree with the others that this might be dangerous for the future if we (hopefully) are going at it.

* Capturing values out of a pattern and binding them to variables if matched.

Where this is very helpful especially with `match`, from the syntax I would read it as a condition only.

$p is Point {x: 3, y: $y}; // read as $p->y === $y but it's $y = $p->y

But this is described differently

$p is Point {y: 37, x:@($x)};

I think it would be more readable on switching the logic (somehow). like:

$p is Point {x: 3, y: $y}; // $p->y === $y
$p is Point {x: 3, y:=> $y}; // $y = $p->y

* Regex pattern

This one is interesting as well ... but I would expect native regex syntax first before introducing it as part of a different RFC. Similar as generics.

Following up I would expect something like this:

    $re = /.*/;  // RegEx object
    $matches = $re->match($v); // preg_match
    $v is $re; // used in pattern matching

which opens up another question: Could we have an interface allowing objects to match in a specific way?

    interface Matchable {
        public function match(mixed $value): bool;
    }

Thanks for working on it!

Marc

Attachment: OpenPGP_0x3936ABF753BC88CE.asc
Description: OpenPGP public key

Attachment: OpenPGP_signature.asc
Description: OpenPGP digital signature

Reply via email to