Re: [RFC] Pattern Matching

From: Date: Mon, 01 Dec 2025 22:21:15 +0000
Subject: Re: [RFC] Pattern Matching
References: 1 2  Groups: php.internals 
Request: Send a blank email to internals+get-129494@lists.php.net to get a copy of this message
On Mon, Dec 1, 2025, at 3:57 PM, Paul Dragoonis wrote: > On Mon, Dec 1, 2025, 9:39 PM Larry Garfield <larry@garfieldtech.com> wrote: >> Hi folks. Ilija and I would like to present our latest RFC endeavor, pattern matching: >> >> https://wiki.php.net/rfc/pattern-matching >> >> You may note the date on the RFC is from 2020. Yes, we really have had this one >> in-progress for 5 years. :-) (Though it was inactive for many of those years, in fairness.) >> Pattern matching was intended as the next follow up to Enums, as it's a stepping stone toward >> full ADT support.. However, we also feel it has enormous benefit on its own for simplifying complex >> comparisons. >> >> This RFC has been through numerous iterations, including a full implementation rewrite just >> recently that made a number of features much easier. We have therefore included two patterns that >> were previously slated for later inclusion but turned out to be trivially easy in the new approach. >> (Variable pinning and numeric comparison.) >> >> Nonetheless, there are two outstanding questions on which we are looking for feedback. >> >> Naturally given the timing, we will not be calling a vote until at least late January, >> regardless of how the discussion goes. So, plenty of time to express your support. :-) > > Hi Larry, > > Looking decent so far. > > match() seems a bit clunky in current state. Is it just your code > example, and you could come with another one? > > The match(true) and repeating of $somevar over and over is the clunky part. > > Normal match($somevar) .. this is clean and works like switch() so > people are happy adopting it .. whereas match() and match() is, look > similar but you have to use them differently ? > > Can you clarify? I think you're misinterpreting the example. The first block under "match() enhancement" is the syntax we propose to have. The second block is what it would decompose to, aka, an explanation of what it means. While you could write the second block, you really shouldn't when the first block is available and better. --Larry Garfield

« previous php.internals (#129494) next »