Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:129500 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 5CB8B1A00BC for ; Tue, 2 Dec 2025 06:26:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1764656795; bh=3fQD22PbTPXPWgzB+wAhX/LASDd4m6DEjR35BxaYn1Y=; h=From:Subject:Date:References:Cc:In-Reply-To:To:From; b=ZPjiqj6nvTaDlFoaXsw5KloxrdUG5OB9tOGMCN9yY0VtXGRtbId4AKAb2hx6RRxBl PEMc92NVC2gh9DptNEYyTnM4/mR48X4fVso/SMsOM0ou1UUVGhUfvhniURP34YlzMF b73yo334gm+nTVp73I2+FFwfn/jFUYwvKNM4zFvtQjal6lkOfm4Mcwsq0qLl+u7xxM HZsHFeWVVSWgZDQqmWvF8NmPW0V3CcMl4pMGlbbOgxyUpVFZCusA9utar2J6xs8Cvj MMuPnf4H42lI5buD4KAlzm2Jhui5axIVaHyPtBQ4jH5WaQmj68NaYHtm4TsjfbxcPl OWl11tfJ8B46Q== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id EE78F180056 for ; Tue, 2 Dec 2025 06:26:31 +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.6 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,T_SPF_TEMPERROR autolearn=no autolearn_force=no version=4.0.1 X-Spam-Virus: No X-Envelope-From: Received: from mail-ej1-f43.google.com (mail-ej1-f43.google.com [209.85.218.43]) (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 ; Tue, 2 Dec 2025 06:26:28 +0000 (UTC) Received: by mail-ej1-f43.google.com with SMTP id a640c23a62f3a-b735ce67d1dso840495166b.3 for ; Mon, 01 Dec 2025 22:26:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1764656782; x=1765261582; darn=lists.php.net; h=to:in-reply-to:cc:references:message-id:date:subject:mime-version :content-transfer-encoding:from:from:to:cc:subject:date:message-id :reply-to; bh=Qo8RVbox8Dali4792K8ZBGlVaWb1w0dKzNf+SO3++FE=; b=MrGNC46//L6S0W7H+8WxmiVbHlO0EA10ABkhEdIQb09TSCwT/Jgc0JBfKk0ULrpHUS madeMii8sFewjS2j4bkq1HDTtBFWm1Wn1B53cZqPnbhZdlTAEo3xR4/TqG0sM9Oaj3Jo JrTYId9UW04lmgTSMI7syhUG5aGHKLr6zsbAhxmd40uro/w1/KXRd7Nkrmy0yvClYzcN MA8sh6gEw19k83z2G/YoXeipcwlykdeQPx/u5/hcyZM2QeF4RmkohbAFRYqAUfen0kWv yL5m5zYg1FFxfYVyBoQXC0LCamg7QH9OVHq+xP8QbCCW27F28QChsBWmE0bHZ2TgNdnZ Qbyg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764656782; x=1765261582; h=to:in-reply-to:cc:references:message-id:date:subject:mime-version :content-transfer-encoding:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=Qo8RVbox8Dali4792K8ZBGlVaWb1w0dKzNf+SO3++FE=; b=WEIH0tvQBqz6lme4V11iU0eEeJT8R3cEE0qR9D4IGYoeEWvx7kfBzWXDu1IT13gfpy GWOqYnhdG88l2lN9YCHcNf089a0tv8JkFySUMCY6Br6Aa8eCE2/ubLwvJol8Liv4qG84 HvUoD7+W3eQFkSlpGf2mAhAUU08kuh9z5ahcmkvp1uWrLDHxEj2a0tyPxQYZaBAG/4yL 4066w5MYnlPdWMTrEGJ0vCCMEgxw5nmTEeCOL5n85PibMMgV+UG6XQOYBGJJYsgRFXO8 ruZ8U1fHlu8LluGP8qa8PtlIDYv6SVLye5Milm4QU4Z2UX5BK+doqpVfXWcUbLg6KzxW 17Iw== X-Gm-Message-State: AOJu0YwzmDI2cPRyRK8jqV/yON372zHfIXwa/bKZjkb/ZAVRjrMV1BFk eyFbTWqrSUEbfS4MPW56dwOCRBFv1b+inhq35Cs2plScQ6V5tgywbPW76Tw08w== X-Gm-Gg: ASbGncsWgOC/9C8qj/SSFd4svpGeTJrZ8rHK78qE8HKn3A/nZQ6T04x+SA6srgzYzEI 3hSrw5eKquPnZYrNuJOrOuOQIMXtjc/nHPlFqoSF1lwTlF/IVpb3otZT/gvYZ4adbRbw8S5w/0R ZzvwNi8hfKb+dsk0OqV1Dm8nJ4jJ9b/iHJgfapKKr/HfZLIMj+qZo4fb7djMyYMfCti5InaeuaK Of46OHnXWjIcIKkToQQQCU0C4GGkFt7Yll/5QJijRPl1y3PqbbBHNj01iQoMebkOomAX7MgrnKE vPPcvXLe7MrW5bGuIwhLfbgr08MqPtScntqmAhYGATmkY5swH+qHCGOhyWrv6ExN3zOOstqRa8s t9t84Evdm1LFY6B7fwfDd00cbN0pNt8uZ+2uhHPPNZXLKqOWEh9+0sIDHe6E4sDFCd34AzU2NxY zRwn31+dfj6ajOqr0TTzM34f3d8Pgc8BsKCRsXDdOf X-Google-Smtp-Source: AGHT+IEMcuiKKe7tfrvqqAMjtwuGDJdoB4o0fbm+hKgzULXFR917LYGME+FFIVKW9+SjvvtwQvjZvg== X-Received: by 2002:a17:907:9706:b0:b73:42df:27a with SMTP id a640c23a62f3a-b76c53510a0mr3211362166b.1.1764656782206; Mon, 01 Dec 2025 22:26:22 -0800 (PST) Received: from smtpclient.apple ([178.134.17.116]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-b76f51c67e2sm1442203766b.27.2025.12.01.22.26.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Dec 2025 22:26:20 -0800 (PST) X-Google-Original-From: Dmitry Derepko Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Precedence: list list-help: list-unsubscribe: list-post: List-Id: x-ms-reactions: disallow Mime-Version: 1.0 (1.0) Subject: Re: [PHP-DEV] [RFC] Pattern Matching Date: Tue, 2 Dec 2025 10:26:08 +0400 Message-ID: References: Cc: php internals In-Reply-To: To: Larry Garfield X-Mailer: iPhone Mail (23B85) From: xepozzd@gmail.com (Dmitry Derepko) > On Dec 2, 2025, at 1:38=E2=80=AFAM, Larry Garfield wrote: >=20 > =EF=BB=BFHi folks. Ilija and I would like to present our latest RFC endea= vor, pattern matching: >=20 > https://wiki.php.net/rfc/pattern-matching >=20 > You may note the date on the RFC is from 2020. Yes, we really have had th= is one in-progress for 5 years. :-) (Though it was inactive for many of tho= se 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 al= so feel it has enormous benefit on its own for simplifying complex compariso= ns. >=20 > This RFC has been through numerous iterations, including a full implementa= tion rewrite just recently that made a number of features much easier. We h= ave therefore included two patterns that were previously slated for later in= clusion but turned out to be trivially easy in the new approach. (Variable p= inning and numeric comparison.) >=20 > Nonetheless, there are two outstanding questions on which we are looking f= or feedback. >=20 > Naturally given the timing, we will not be calling a vote until at least l= ate January, regardless of how the discussion goes. So, plenty of time to e= xpress your support. :-) >=20 > -- > Larry Garfield > larry@garfieldtech.com Thank you for the RFC and that you included option with match and individual= IS=E2=80=99s, I think it would be preferable option not to break the match c= onstruction.=20 Regarding the patterns, is there a way to declare and reuse the patterns? As= sign it to a variable and use it as =E2=80=9Cis $pattern=E2=80=9D or somethi= ng like that. Maybe as a separate class =E2=80=9C$pattern->match($var)=E2=80= =9D.=20 While it=E2=80=99s not reusable it looks like it has a limited scope to use i= t, otherwise regular replacements preferred.=20 --=20 Best regards,=20 Dmitrii Derepko.=20 @xepozz=