Re: [RFC] Pattern Matching

From: Date: Mon, 26 Jan 2026 10:53:50 +0000
Subject: Re: [RFC] Pattern Matching
References: 1 2 3 4 5  Groups: php.internals 
Request: Send a blank email to internals+get-129929@lists.php.net to get a copy of this message
On Mon, Jan 26, 2026 at 5:48 AM Morgan <weedpacket@varteg.nz> wrote: > On 2026-01-26 07:44, Larry Garfield wrote: > > > > With per-arm, you can opt-in to pattern matching individually, at the > cost of having to remember to repeat the keyword on every line. With > per-block, you only have to add the keyword once at the cost of not being > able to selectively use patterns or identity matching. > > > > Which tradeoff is better is the option question. (Ilija and I disagree > on which to go with.) Or, if someone can suggest a way to allow automatic > detection reliably, that would also be most welcome. :-) > > > > If it had to be one or the other [...] Does it have to be one of the other though? Can't we have both? ```php $result = match ($somevar) { is Foo => 'foo', // This matches against the pattern Foo, which is a class name. Bar => 'bar', // This matches === against the constant Bar, whose value is whatever. }; ```php ```php $result = match ($somevar) is { Foo => 'foo', // This matches against the pattern Foo, which is a class name. Bar => 'bar', // This matches against the pattern Bar, which is also a class name }; ``` ```php $result = match ($somevar) is { is Foo => 'foo', // This is an error (?) }; ```php We already have somewhat similar behaviour with readonly (for properties) and abstract (for methods) class modifiers. When you specify it on a class, it applies to all members, but you can also specify it on an individual member. -- Best regards, Bruce Weirdan mailto: weirdan@gmail.com

« previous php.internals (#129929) next »