Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:129947 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 E150F1A00BC for ; Wed, 28 Jan 2026 20:25:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1769631925; bh=LjR1z9F2Gg6WbI5ScQy8F0lEzeMbEhbhI3KDQQWV3lI=; h=Date:From:To:In-Reply-To:References:Subject:From; b=ezZlcX3aqtPASdXpM1jkJnmFH8u/pCGt5CiqFoYFPjZoitipo1LgeHPbdIHJGKqby kahKi7tYsIuDPLBoj7dJzIo/gi6m+fbKlprNvXCZUx2HUq7hSu9W9vZUzqbG44LsjI lpO1tZRoxtPPhe74dDDJeTuALFRpAm4xsVclZfPehG7WEqt1YKL6NIdx+0rZzqf5HT OxRdhXp4eCLstR2FzkpbLUdU0g+9fNIXeOU1FQ0KxlSg/Jy1NIpIcDchleXsxDFksC gfz4BdthYZQIvvShh9Uki/Zu1fYAT2JIS1WHDwhZHdx5xL0xKmYhSigGpdSXUsVvCB Kx6KHVKcun5zg== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 72EF7180086 for ; Wed, 28 Jan 2026 20:25:24 +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, HTML_MESSAGE,SPF_HELO_PASS,SPF_PASS autolearn=no autolearn_force=no version=4.0.1 X-Spam-Virus: No X-Envelope-From: Received: from outbound.st.icloud.com (p-east2-cluster5-host5-snip4-8.eps.apple.com [57.103.79.91]) (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 ; Wed, 28 Jan 2026 20:25:24 +0000 (UTC) Received: from outbound.st.icloud.com (unknown [127.0.0.2]) by p00-icloudmta-asmtp-us-east-1a-20-percent-2 (Postfix) with ESMTPS id 9776F18012C0; Wed, 28 Jan 2026 20:25:17 +0000 (UTC) Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=me.com; s=1a1hai; t=1769631918; x=1772223918; bh=97FyNJNhlNR91RdKgzvjf9JHwcYucFdBCrjZSIiJlQY=; h=Date:From:To:Message-ID:Subject:MIME-Version:Content-Type:x-icloud-hme; b=0iBgZdLAwKy/IsI72slO/Es9Vk5XNw+2PSW+qRuCDnzX7yggAUS0APcU+pkEc9PlBVk2/xohiVwD6YLoU2QSxsRaycHTr0PKYNFMXKebhhNciifGr5zfWUuHP7iAQccUe3j9cCosRLnYe0ZD/l7Oe6xknPpyu4F+DPHKDIDuYrM21mG412PS8u3LGhb8BaL/dNbf2PthhKkX8z2uQzmOSOdt7S8qGxx7AAP0MrJ6mqiBahF0sMa+9yvujQQJlsGrlwiEaWX3fFkCyC6lgrrIPzgioY8Uj+awqsWft7XzkRmKX4i5quOL3/pydRGdrdeaiORPwX/yh41H42mouXfoEg== Received: from [192.168.1.170] (unknown [17.42.251.67]) by p00-icloudmta-asmtp-us-east-1a-20-percent-2 (Postfix) with ESMTPSA id B617018000A8; Wed, 28 Jan 2026 20:25:16 +0000 (UTC) Date: Wed, 28 Jan 2026 21:25:09 +0100 To: Larry Garfield , internals@lists.php.net Message-ID: <5c291a56-baee-48db-93a8-27c8dd903bc0@Spark> In-Reply-To: <56dce794-a512-421a-a8d2-91a9692c1ab4@app.fastmail.com> References: <56dce794-a512-421a-a8d2-91a9692c1ab4@app.fastmail.com> Subject: Re: [PHP-DEV] [RFC] Pattern Matching X-Readdle-Message-ID: 5c291a56-baee-48db-93a8-27c8dd903bc0@Spark Precedence: list list-help: list-unsubscribe: list-post: List-Id: x-ms-reactions: disallow MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="697a70aa_6a5f7029_d0e3" X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwMTI4MDE2OCBTYWx0ZWRfXxBk89+UbZrIx J1kEpgMtpQ5dymIc3HlIso8SCZIrKVwtVL7EGq78CdXFHkak/SMBPwtswgOTw9CcE1kIp2b+/xO Kq+aLR/73cec+1jYNTaz84P3JUT1p42i0jt67+k7WRLUZOR/XDdDinWs078lTFiipDjVx9eQKXX 3d78RSKfU2B8/+mNKUGk8pX4PuBhFux1PRVJcHYamYRKAx/+Lfhci7D0KQmbA+gymlFxqPJ0f/f DzHIezBiTzsa83o5zmRUkuCAJE+OsCmMXGaCYqYm4QghnimQzxWMvV0Pd+gXAaHKy5InMUQUT8N Uekr0oWJV41JoW0cEBO7g0m8cqkCHxVm8894FE4XQe3H/tH8wrxw1dZ3XenArY= X-Authority-Info-Out: v=2.4 cv=EbnFgfmC c=1 sm=1 tr=0 ts=697a70ae cx=c_apl:c_apl_out:c_pps a=YrL12D//S6tul8v/L+6tKg==:117 a=YrL12D//S6tul8v/L+6tKg==:17 a=vUbySO9Y5rIA:10 a=x7bEGLp0ZPQA:10 a=xKl34KcbpAAA:10 a=VkNPw1HP01LnGYTKEx00:22 a=67BIL_jfAAAA:8 a=KVQS9QH4LQgmUr2nRr4A:9 a=QEXdDO2ut3YA:10 a=SSmOFEACAAAA:8 a=KV8xmtTuKYhmZSO8s2AA:9 a=KDwZVgaPIMgyzHoV:21 a=_W_S_7VecoQA:10 X-Proofpoint-GUID: RYZCv8c7R1-YCke0XzET_6NYaCkAZhUk X-Proofpoint-ORIG-GUID: RYZCv8c7R1-YCke0XzET_6NYaCkAZhUk X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1121,Hydra:6.1.51,FMLib:17.12.100.49 definitions=2026-01-28_06,2026-01-28_03,2025-10-01_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 mlxscore=0 bulkscore=0 lowpriorityscore=0 malwarescore=0 clxscore=1011 adultscore=0 phishscore=0 mlxlogscore=999 spamscore=0 classifier=spam authscore=0 adjust=0 reason=mlx scancount=1 engine=8.22.0-2601150000 definitions=main-2601280168 X-JNJ: AAAAAAAByR1qvVDWsrbH14sILeS6QmQ12/s9S4C0ZsWgNTb6rLLjeq7bDJKmZAgF9/ODuiz3kvG3K6hTlOmJkQy0Pj9lyHSWwTAyEl8grixLSzor0DpxjTU1KKrd0mc9BICdumwGy7ReIj7dYER4ejjoRSLMoAinhr3Fdy0JohFlAyZUbqxQGAz2e5MU1lzX1YdX+6cDNvnNvnyxmIrdyhvCdm1krjNL7wvy3DzQrJad8om/45P3EYVEb0loM7RQw4zzzM43/5q/+dFQtC0KjYqGrjXsRwCn8Fv9zTbw4oDi1CqFypl9G26MEuY5o6fVb/lSyt2Hq/xHWOcYqNjZkCbivD3yU/2QqbmnYaS+Tb/zMvRuayW1RjTBYEW4vNmNbQpH2/jWPJAdH9K2pQ1QkFEFLw7AmyWux92M18uDtOOlUBEiD8NfN0a+kxYdTvLW4z+21smDD4hdilMD1dM82glMKzyjyqqOVZHCOgyqfR4MIH8DwNqGWo0UpgdRSiNhUtYVhbEfBJxZ7V1FFhqrbmEEMUjxYHgS8DvV+1LrxrBlR9Xk/sx1GM0Q11R5RDpldUH1MMexM8+58ULcG2hUt2vGt/rk2ZKd3UBbOKdlGzho26FZ5FroVqQLa/6X From: jordikroon@me.com (Jordi Kroon) --697a70aa_6a5f7029_d0e3 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Hi, > 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. I prefer to have one syntax. The most flexible one is individual arms. An= d to me it also looks more clean from the functional side. If we support both we should also disallow the use of mixing all arms and= individual arms. Thus this syntax should return an error. =24result =3D match (=24somevar) is =7B // Error=21 is =46oo =3D> 'foo', is Bar =3D> 'bar', is Baz=7CBeep =3D> 'baz', =7D; > Positional array patterns. How picky should the pattern matching be for= list-esque arrays=3F There's 3 options listed in the R=46C as possible w= ays forward, so I won't repeat them here but just provide a link: > > https://wiki.php.net/rfc/pattern-matching=23positional=5Farray=5Fenforc= ement =46rom a cost perspective it would be best to keep it to a minimum. But a= rray=E2=80=99s exist in different styles where it matters to have at leas= t a few edge-cases covered. Especially when converting between data forma= ts (Serialise, JSON, ..) I would personally discourage to return true with the following cases: Given: =24a =3D =5B'a', 'b', 'c'=5D; =24a is =5B2 =3D> 'c', 0 =3D> 'a', 1 =3D> 'b'=5D; Should return =60false=60, because when converting to other data formats.= The style will change from numerical to key'ed (associative style). The = same applies to the inverse. Though given: =24a =3D =5B'a', 'b', 'c'=5D; =24a is =5B0 =3D> 'a', 1 =3D> 'b', 2 =3D> 'c'=5D; Should return =60true=60, because they keep the numerical order. And when= converted it will be the same. > 3. Do we want to have a pattern for =22match an object's properties wit= hout specifying what type the object has to be=3F=22 If so, what syntax s= hould it be=3F Just omitting the class name (producing =60=24o is =7Bx: 1= =7D=60 ) is not possible. We tried. :-) Options include: > > =60=24o is =5F(x: 1)=60 > =60=24o is object(x: 1)=60 I am not a favour of using shorthands. They tend to make code more diffic= ult to read and understand.=C2=A0=C2=A0Thus =60=24o is object(x: 1)=60 is= what I suggest as well. 4. > =C2=A0The variable pinning syntax. There's been some concerns about it = being non-obvious, which is valid. The main argument for it is =22it's wh= at Ruby does=22, which is not the most compelling argument, but it's not = invalid. I strongly agree that the the =60=5E=60 is not a good choice. It is diffi= cult to understand,I personally think pinning at all is not important. Th= ough if we proceed forward on this =60=7B=24x=7D=60 would make most sense= since it is more in line with string interpolation syntax. And like you = mentioned it opens more possibilities. Regards, Jordi --697a70aa_6a5f7029_d0e3 Content-Type: text/html; charset="utf-8" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline
Hi,
1. match() statements. There's two ways we could do this: All-branches, = or individual branches. This is particularly important as, in practice, w= e expect match() to be the most common use of patterns.
I prefer to have one syntax. The most flexible one = is individual arms. And to me it also looks more clean from the functiona= l side.

If we support both we should also disallow the use of mixing all arms and= individual arms. Thus this syntax should return an error.
=24result =3D match (=24somevar) is =7B // Error=21
    is =46oo =3D> 'foo',
    is Bar =3D> 'bar',
    is Baz=7CBeep =3D> 'baz',
=7D;

Positional array patterns. How picky should the pattern matching be for = list-esque arrays=3F There's 3 options listed in the R=46C as possible wa= ys forward, so I won't repeat them here but just provide a link:

https://wiki.php.net/rfc/pattern-matching=23positional=5Farray=5Fenforcem= ent

=46rom a cost perspective it would be best to keep it to a minimum. But a= rray=E2=80=99s exist in different styles where it matters to have at leas= t a few edge-cases covered. Especially when converting between data forma= ts (Serialise, JSON, ..)

I would personally discourage to return true with the following cases:
Given:
=24a =3D =5B'a', 'b', 'c'=5D;
=24a is =5B2 =3D> 'c', 0 =3D> 'a', 1 =3D> 'b'=5D;
Should return =60false=60, because when converting = to other data formats. The style will change from numerical to key'ed (as= sociative style). The same applies to the inverse.

Though given:
=24a =3D =5B'a', 'b', 'c'=5D;
=24a is =5B0 =3D> 'a', 1 =3D> 'b', 2 =3D> 'c'=5D;
Should return =60true=60, because they keep the numerical order. And when=
 converted it will be the same.

3. Do we want to have a pattern for =22match an object's properties with= out specifying what type the object has to be=3F=22 If so, what syntax sh= ould it be=3F Just omitting the class name (producing =60=24o is =7Bx: 1=7D= =60 ) is not possible. We tried. :-) Options include:

=60=24o is =5F(x: 1)=60
=60=24o is object(x: 1)=60&=23160;
I am not a favour of using shorthands. They tend to= make code more difficult to read and understand.&=23160;&=23160;Thus =60= =24o is object(x: 1)=60 is what I suggest as well.


4.
&=23160;The variable pinning syntax. There's been some concerns about it= being non-obvious, which is valid. The main argument for it is =22it's w= hat Ruby does=22, which is not the most compelling argument, but it's not= invalid.
I strongly agree that the the =60=5E=60 is not a go= od choice. It is difficult to understand,I personally think pinning at al= l is not important. Though if we proceed forward on this =60=7B=24x=7D=60= would make most sense since it is more in line with string interpolation= syntax. And like you mentioned it opens more possibilities.

Regards,
Jordi


--697a70aa_6a5f7029_d0e3--