Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:129908 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 lists.php.net (Postfix) with ESMTPS id 5DCF61A00BC for ; Fri, 23 Jan 2026 19:48:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1769197738; bh=PkW4NMBYf5eKkFAr7XZKsuxfxdmX/D3KP12FDlWqjvs=; h=Date:From:To:In-Reply-To:References:Subject:From; b=hYrNl80L3weoYA4eDQZcsbKR1mlxsUAKhlQhSmHLvQXLFPYasKsjwRUz8sD1rO6YW fmVgZQoThxGBE9UO5wbwOrwOllNABiFuTNm9yy9sBb6wzI3nPv2uqU7ACYW9J2KoIq rTAbRQ/kVPRViutg5GbFUGRYeMpPQehZIJyBXoGvqYOBo6RaBqs5pA/hZCroSoYiyG M+LcK/IoMbLywx5wRUKZ9O8CP1pMJanWIJN0DMPcau+QR4jblUnn/kMwZNPQknhF0y /hw4+okdJfpf453zawnUgIDrAtPlNn91pro+LbVbbTtFplatk4X57QhBp5KqjU/R/E zyu1sewvHKflQ== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id E91A318055E for ; Fri, 23 Jan 2026 19:48:57 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-0.1 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_MISSING,RCVD_IN_DNSWL_LOW, SPF_HELO_PASS,SPF_NONE autolearn=no autolearn_force=no version=4.0.1 X-Spam-Virus: No X-Envelope-From: Received: from fout-a1-smtp.messagingengine.com (fout-a1-smtp.messagingengine.com [103.168.172.144]) (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 ; Fri, 23 Jan 2026 19:48:57 +0000 (UTC) Received: from phl-compute-04.internal (phl-compute-04.internal [10.202.2.44]) by mailfout.phl.internal (Postfix) with ESMTP id 240DCEC00C0 for ; Fri, 23 Jan 2026 14:48:52 -0500 (EST) Received: from phl-imap-02 ([10.202.2.81]) by phl-compute-04.internal (MEProxy); Fri, 23 Jan 2026 14:48:52 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= garfieldtech.com; h=cc:content-transfer-encoding:content-type :content-type:date:date:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to; s=fm2; t=1769197732; x=1769284132; bh=9a6z4gMGWSOJe+gQ7BGvh VQZ3eEdzdIsU1MjBbEPSi4=; b=kXrxJ9Vdu+5e4WjmbubQvudRVEJrIPEPja/XN X2Umd8HZbT/S999BbdqNJqQ7WmWHB1VEUmXWsQlBVuL2gZ2Uyn9XnMqQFV8iIztk Pbh4P2Um4iqih5drX3npwxRoR8zrKqzPCc7OfzyLyohotFv+buHV91YT+asks/Sz 5r5OsqKzIzdDRhXeBjY2/bYO3hq2b0kJzH8VLjhMS/lUuODY5Zd+50RvLlGj0pwJ fg69629soH9r+PMpQuu1VFCGXdsSDd+xMdlhQf31fAB06rsSk7nlLkiYdFr3uphV N2JSBrozM2Rjt+P1IX0zyoaE2IXSENag8/yblYSy15E65JLEw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm2; t=1769197732; x=1769284132; bh=9 a6z4gMGWSOJe+gQ7BGvhVQZ3eEdzdIsU1MjBbEPSi4=; b=CJxZ6IidL8EUkEl97 o2CZzsKo5k47LXDCNCJxBK9+fD2XRgcPeoHIeiCyDO8Y9uGsMb3FhaRe+vZGVyEc 22r23Aa7fx/0/jCV2g0CX/31iBI/Pez2cOZTUB49NVElSusLGhdfHxC26xw4cyTA RY+oy1vrh9PRmA+ZiSSFxxnAZkt7yYSkW5JGJ7jppoEOlwabU63othqL1ZV0eA18 dhPiL+szKZUVaStB4/gmN/8eMmnybLtgoi82FdB2H5+pCqqf4kZdFdPCW5dgWiap aJ3iF+FQKsx6bROULGEwnHUvDpvYWy3D36pawUb30Ke8sU+yb06yasexjSxSvRqC 6C8DA== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefgedrtddtgddugeelledvucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfurfetoffkrfgpnffqhgenuceu rghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujf gurhepofggfffhvffkjghfufgtgfesthejredtredttdenucfhrhhomhepfdfnrghrrhih ucfirghrfhhivghlugdfuceolhgrrhhrhiesghgrrhhfihgvlhguthgvtghhrdgtohhmqe enucggtffrrghtthgvrhhnpeeuvedvudfhffffhfelueehvdejvefgleegteegffetudef leehgeefvdehgeelteenucffohhmrghinhepphhhphdrnhgvthenucevlhhushhtvghruf hiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehlrghrrhihsehgrghrfhhivghl ughtvggthhdrtghomhdpnhgspghrtghpthhtohepuddpmhhouggvpehsmhhtphhouhhtpd hrtghpthhtohepihhnthgvrhhnrghlsheslhhishhtshdrphhhphdrnhgvth X-ME-Proxy: Feedback-ID: i8414410d:Fastmail Received: by mailuser.phl.internal (Postfix, from userid 501) id D8030700069; Fri, 23 Jan 2026 14:48:51 -0500 (EST) X-Mailer: MessagingEngine.com Webmail Interface Precedence: list list-help: list-unsubscribe: list-post: List-Id: x-ms-reactions: disallow MIME-Version: 1.0 X-ThreadId: A0wUJIXp2QXJ Date: Fri, 23 Jan 2026 13:48:31 -0600 To: "php internals" Message-ID: <56dce794-a512-421a-a8d2-91a9692c1ab4@app.fastmail.com> In-Reply-To: References: Subject: Re: [PHP-DEV] [RFC] Pattern Matching Content-Type: text/plain Content-Transfer-Encoding: 7bit From: larry@garfieldtech.com ("Larry Garfield") On Mon, Dec 1, 2025, at 3:36 PM, Larry Garfield 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. :-) Happy New Year! Tim brought up some interesting points around parsing edge cases, which we're still discussing off list. Once we have a proposal (or multiple) to consider, we'll get back to that part. Meanwhile, there's a few outstanding issues that we do still want/need broader feedback on. Even if you just want to state a bikeshed preference, please do so. (Though an explanation of why is always helpful.) 1. match() statements. There's two ways we could do this: All-branches, or individual branches. This is particularly important as, in practice, we expect match() to be the most common use of patterns. // All-branches: $result = match ($somevar) is { Foo => 'foo', Bar => 'bar', Baz|Beep => 'baz', Qix, Nox => 'qix', }; // Individual branches $result = match ($somevar) { is Foo => 'foo', is Bar => 'bar', is Baz|Beep => 'baz', is Qix, Nox => 'qix', }; The idea of the second being that, if you want just an identity match, you can skip adding `is` on just that one arm. While it would be lovely to do that automatically, we cannot differentiate between a class name and a constant so that's not really feasible. Of note, most language with this functionality have no "non-pattern" equivalent of match(), so the issue doesn't come up. The only one that does, Ruby, uses a different prefix keyword depending if it's pattern or equality based, BUT you have to use the same keyword for all branches. 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 3. Do we want to have a pattern for "match an object's properties without specifying what type the object has to be?" If so, what syntax should it be? Just omitting the class name (producing `$o is {x: 1}` ) is not possible. We tried. :-) Options include: `$o is _(x: 1)` `$o is object(x: 1)` // Your suggestion here. 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. Please do weigh in and help us decide on a way forward for these. --Larry Garfield