Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:129929 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 470DC1A00BC for ; Mon, 26 Jan 2026 10:54:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1769424867; bh=TYXU3aqfvLsFRJLZ0WmIkugOtVt3XFks6U0HFfnZM3k=; h=References:In-Reply-To:From:Date:Subject:Cc:From; b=A+rRKWOMeFJWiUNLiao9SxWPcQ2IFAIO4EqcWQn0Igql3X6LzjiY+G+xs4eKpMy1J S8oLzaHNwV1XXwYg1eVneNLgFLsP0GOvl4R+uk75QlXrcqTd4sh4IRy8urTqTviqc9 RUjP1C1sUzL1YhBY7xNHBPDGckScvI3Y3XBj0qHB4HjwOlv3GEH0xLH5wZOf4aKHm7 ikkp0bnm7aJwV7XczTzHiWVs8kWLHciOhE46k7cDEGaLBZsGE5TDmN1Xz+v9VXTYZ3 NYnMTcp9mCjN4PkQi8/rhMXfcwDpqoHXMrEpEI1mhB6pJ7qEg1S1qbouvWRnQCkQKC I2pxrZBCG1qLQ== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id E4996180081 for ; Mon, 26 Jan 2026 10:54:26 +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=4.9 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_50, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS, FREEMAIL_FROM,HTML_MESSAGE,MALFORMED_FREEMAIL,MISSING_HEADERS, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=4.0.1 X-Spam-Virus: No X-Envelope-From: Received: from mail-ej1-f48.google.com (mail-ej1-f48.google.com [209.85.218.48]) (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 ; Mon, 26 Jan 2026 10:54:23 +0000 (UTC) Received: by mail-ej1-f48.google.com with SMTP id a640c23a62f3a-b885a18f620so555495766b.3 for ; Mon, 26 Jan 2026 02:54:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1769424857; cv=none; d=google.com; s=arc-20240605; b=gR7eGACuqTF0VxBc+73BVWoHmPoCpwvXzVTSLLx3Tx+QtFC5rPC1nfKDq5h643uHYt 4IK7Um+rVRaIlUTqLtAfSrsMbZLHG8YGiqd5UKRTZhZV62FD2NsKIluWCS1CYLT7Hi7l ubuxyy1T+q/UCRv7KZoHH7xxl4R6N5uonRJC6jzcn5jP/heoBzOvuO7aUAawIyysGzFg 75a0dWq1mIuK+l/qA+0rXhbWtIVuBoe8j5nV7nQEy98gJ2mFi3aNBbjP2HYz0wZcGFSt epcN6YHvm19gyHQb91YG2vh/vXyU12VpsTxSMOkl2NapKzRdsxI8L54BYIBZ+T5qpe1c nVNQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=cc:subject:message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=tgw0tEL7PWKpcRU9h/pEPa1nXapqF641bL63eWvPets=; fh=lbi0LxXaWVIktIh1B5JKJxPYG7HvBLBpkdTflmrdUVc=; b=PjBICDwGd9eHhCUVNSrCQ+AxO+3GGLOUQn4g+sk/Wlia2JSQYjMfvc9vsJlS1CBphz c2ODkkVhJ1kPFSo46/rZtuv+t3pmPCmeZe/8tHUIVTSP/MDuhtAeXhVNksR5uXCC8V8r JwuoFZPHB2+1daI6zI+GOEjL8/+uPk3vYFxX1XysVVPdv4+h/3iFYVjCOWeuRA2VkxnB ZglyRso8mNpghnsdjToZeUKlosGvs05ZleEyzjQa4ZkUD4BP1ugQbyeV0a7FoaIkUF8w PDynGux3hwtl1MYUmF41X09sdah995f85LFeSkI5tK28Lg/1UOPDaB8Y2Tp51OVVb609 jJZQ==; darn=lists.php.net ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1769424857; x=1770029657; darn=lists.php.net; h=cc:subject:message-id:date:from:in-reply-to:references:mime-version :from:to:cc:subject:date:message-id:reply-to; bh=tgw0tEL7PWKpcRU9h/pEPa1nXapqF641bL63eWvPets=; b=fAHbvfLWwMK06XxWdZqoisqbj/bL67b5gmY5ZX5E/nlwUkB6skJZu1XA9UN1gjdg4F IghT1opCxvc9diIZ4VTdtSaVof8GncN02PcmCYs8stt8vf3l0mX8x9Ie0fqUPrT38CUZ fe1HYfRYLdN8dAQtF30EhpiQajDdbcuyIWDAMHOD35gsu2juVis1E5S3SGDORWBmhlUy OEFDJPUur4AT3J2r9qwU935nzP6SRpK12lsSXAbOPUaG6cnfita2w51wc8h0L4+g+zwN fA1oczPj5fHroaSx9QuwTkhhZfneaHG4pqxaohiEzHL2Kacnus4iwxbvqxZn9bbD3X63 zbhw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769424857; x=1770029657; h=cc:subject:message-id:date:from:in-reply-to:references:mime-version :x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=tgw0tEL7PWKpcRU9h/pEPa1nXapqF641bL63eWvPets=; b=k9+qnMi5mKDgCncVabDppE1YFm1I5Vhxrl1TVP2z7j0w7xEk494AAeuzqbcD5RZgza S4F+Pm4XowLmWHYEUllT9F7UVyqmOTZ9XrfGRD7DrhqPow5hORlUUHgUOkBNdbq9MZ28 3d8pXrlH67yqTlQacrAiIwrR3xgk7lPxHAepUTQapl4RC00R7dYNVwrjfd2yhNwAvLzg UsD9smukTXSoaV7wt+v4MATSgwzpTRDvCf5LXpSI2Rwn0D3mXfuX1lHQwKwFP/7U7OQX 4Bgfv6Dv0TGaGre4/HhFYNy/SXQC2aBiud46VAAs5NTfFr33p7oBHvJeRGMW9fU963lo 8A0g== X-Gm-Message-State: AOJu0YzrjTb+NkyrM9mIprVtjUGCEat1zZ5Dji6qRvaOqy1545dr6NK/ RRs8vber6sVJocPjJ1kAScR8sFjc7lWbIhYKTwPMTrbuc8jLFUHq0N04kAtaczszTkIwnRIXsCq JI90gTOyY+t4b3/I+JdY3VghngvRXIzXezGL2 X-Gm-Gg: AZuq6aKVOvYeKt4CIurnPembMHUS23SsBWloPWvEfp2UIdfoZBuCl846XYSDZ0drCSB 86D//eTi4h24/dgMD3KDFaBoxIwOVSmt5OHhmkJDaR3R8I6CRkUCV3/nEIEGzrZq+XXHXnIdBnU AYnm4Mzbxn4Ed8ojqRdVCDZ+v2Qr9D/ZWYep53/Kf81zzXHx+AXeLFomDUAtoD3OYzAXdn349Zq pyo75hCdQ0TYtCTE9+IBb2UZ2effDvPKiyS20h3f5fXQzcBGuPgiLqqx6A8hvWGDpoIgkz90A/u VYIgkRnKAiYs52Ud75iGIBBfQD0= X-Received: by 2002:a17:907:748:b0:b80:5ae7:5d94 with SMTP id a640c23a62f3a-b8cfee25899mr254365966b.7.1769424857004; Mon, 26 Jan 2026 02:54:17 -0800 (PST) Precedence: list list-help: list-unsubscribe: list-post: List-Id: x-ms-reactions: disallow MIME-Version: 1.0 References: <56dce794-a512-421a-a8d2-91a9692c1ab4@app.fastmail.com> <23093833-bdd2-442d-86b8-9ef492c51ad1@app.fastmail.com> <49cb415d-adb9-408d-82af-b71f6de234ad@varteg.nz> In-Reply-To: <49cb415d-adb9-408d-82af-b71f6de234ad@varteg.nz> Date: Mon, 26 Jan 2026 11:53:50 +0100 X-Gm-Features: AZwV_QjJUkIltth38ECK6rRL4SvYKdxMD9QZW5mBud7eZEeuke07gEeHKBvFWYI Message-ID: Subject: Re: [PHP-DEV] [RFC] Pattern Matching Cc: internals@lists.php.net Content-Type: multipart/alternative; boundary="0000000000000efeb2064948544b" From: weirdan@gmail.com (Bruce Weirdan) --0000000000000efeb2064948544b Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Mon, Jan 26, 2026 at 5:48=E2=80=AFAM Morgan 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 automati= c > 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 =3D match ($somevar) { is Foo =3D> 'foo', // This matches against the pattern `Foo`, which is = a class name. Bar =3D> 'bar', // This matches =3D=3D=3D against the constant `Bar= `, whose value is whatever. }; ```php ```php $result =3D match ($somevar) is { Foo =3D> 'foo', // This matches against the pattern `Foo`, which is a class name. Bar =3D> 'bar', // This matches against the pattern `Bar`, which is als= o a class name }; ``` ```php $result =3D match ($somevar) is { is Foo =3D> '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. --=20 Best regards, Bruce Weirdan mailto: weirdan@gmail.com --0000000000000efeb2064948544b Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable


On Mon, Jan 26,= 2026 at 5:48=E2=80=AFAM 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.=C2=A0 With = per-block, you only have to add the keyword once at the cost of not being a= ble to selectively use patterns or identity matching.
>
> Which tradeoff is better is the option question.=C2=A0 (Ilija and I di= sagree on which to go with.)=C2=A0 Or, if someone can suggest a way to allo= w 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 =3D match ($somevar) {
=C2=A0 =C2=A0 is Foo =3D> 'foo', // This matches against the pat= tern `Foo`, which is a class name.
=C2=A0 =C2=A0 Bar =3D> 'bar',=C2=A0 =C2=A0 =C2=A0// This matches= =3D=3D=3D against the constant `Bar`, whose value is whatever.
};
```php

```php
$result =3D match ($= somevar) is {
=C2=A0 =C2=A0 Foo =3D> 'foo', // This matches a= gainst the pattern `Foo`, which is a class name.
=C2=A0 =C2=A0 Bar =3D> 'bar', // This matches against the patter= n `Bar`, which is also a class name
};
```

```php
$result =3D= match ($somevar) is {
=C2=A0 =C2=A0 is Foo =3D> 'foo', // This is an error (?)
};
```php

We already have somewhat similar b= ehaviour with `readonly` (for properties) and `abstract` (for methods) clas= s modifiers. When you specify it on a class, it applies to all members, but= you can also specify it on an individual=C2=A0member.

=



--
=C2=A0 Best regards,
=C2=A0 =C2=A0 =C2=A0 Bruce Weirdan=C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=C2=A0 mailto:weirdan@gmail.com
--0000000000000efeb2064948544b--