Re: [RFC] Pattern Matching

From: Date: Sat, 24 Jan 2026 18:25:17 +0000
Subject: Re: [RFC] Pattern Matching
References: 1 2  Groups: php.internals 
Request: Send a blank email to internals+get-129914@lists.php.net to get a copy of this message
Hi Am 2026-01-23 20:48, schrieb Larry Garfield:
The idea of the second being that, if you want just an identity match, you can skip adding is on just that one arm.
I don't understand what that is trying to say.
2. Positional array patterns. How picky should the pattern matching be for list-esque arrays? There's 3 options listed in the RFC as possible ways forward, so I won't repeat them here but just provide a link: https://wiki.php.net/rfc/pattern-matching#positional_array_enforcement
I expect "list patterns" to be reasonably short, such that array_is_list() would effectively be constant-time after checking whether the number of elements matches up. As such I would prefer (1) "Include the list check, accept the cost".
$o is object(x: 1)
That would be okay, but no strong feelings.
4. The variable pinning syntax. There's been some concerns about it being non-obvious, which is valid. The main argument for it is "it's what Ruby does", which is not the most compelling argument, but it's not invalid. Is there some other syntax that would work better? Ilija has pondered {$x}, which would then potentially allow simple expressions inside the pattern within the {}. I am a little scared of the scope creep potential. :-) But we're open to having this discussion, so please discuss.
As I think I said before, I don't need variable pinning at all, but ^ in particular is terrible. {} would be okay, but I prefer just not making a decision for now. Best regards Tim Düsterhus

« previous php.internals (#129914) next »