Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:102277 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 72044 invoked from network); 15 Jun 2018 14:55:00 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 15 Jun 2018 14:55:00 -0000 Authentication-Results: pb1.pair.com smtp.mail=theodorejb@outlook.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=theodorejb@outlook.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain outlook.com designates 40.92.14.52 as permitted sender) X-PHP-List-Original-Sender: theodorejb@outlook.com X-Host-Fingerprint: 40.92.14.52 mail-oln040092014052.outbound.protection.outlook.com Received: from [40.92.14.52] ([40.92.14.52:46413] helo=NAM05-DM3-obe.outbound.protection.outlook.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id E8/74-29356-C33D32B5 for ; Fri, 15 Jun 2018 10:54:53 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=PUyD3nU60lqhg8ux7UxGhcdNtSSH+Y9cWPCNH3vUp48=; b=jGXPLW8HMB8z+heC83qv602T1sI/J5dfgm5AHuUTvTRkx/RI52LwfULwxTaUwAUOxDwCkoWpDfXHDtEhGdm5jjsV0RTJ8Bm+FUe9hioQXJCV5lXoqSsu/FuT+M9rqT+BNkLHvwsodFdfwFZvisNFwjX8+6YOizuzontkIF4oaD8RyAd9u7/hW1mJrNWKZUN99zFAOU6qUAsTn28GdXWDFv3UJxgosSCJJNX3+PIvO7kNNH87wVgeKkjs1P3q+aUOO+liIpsmeZEuK8duuSma9/75RD/TVb5gtHHHL0mib4wCGdmONVzh0U6xpT/DaPKo0PFfJoHBG4VZaxNN+4KT7Q== Received: from CO1NAM05FT028.eop-nam05.prod.protection.outlook.com (10.152.96.57) by CO1NAM05HT187.eop-nam05.prod.protection.outlook.com (10.152.97.133) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.20.884.14; Fri, 15 Jun 2018 14:54:49 +0000 Received: from CY4PR18MB1048.namprd18.prod.outlook.com (10.152.96.55) by CO1NAM05FT028.mail.protection.outlook.com (10.152.96.138) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.20.863.7 via Frontend Transport; Fri, 15 Jun 2018 14:54:49 +0000 Received: from CY4PR18MB1048.namprd18.prod.outlook.com ([fe80::6070:e0aa:b389:4f19]) by CY4PR18MB1048.namprd18.prod.outlook.com ([fe80::6070:e0aa:b389:4f19%9]) with mapi id 15.20.0863.016; Fri, 15 Jun 2018 14:54:48 +0000 To: Sara Golemon , Nikita Popov CC: PHP internals Thread-Topic: [PHP-DEV] Strict switch statements Thread-Index: AQHUA5uya6OuJ5pdqES/i1/trBXBb6Rfbi2AgABoQICAAY02Xw== Date: Fri, 15 Jun 2018 14:54:48 +0000 Message-ID: References: , In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-incomingtopheadermarker: OriginalChecksum:7B213B7961A323F24B27853152179A1184E0C159393F2B78F24FAF36DFEDC039;UpperCasedChecksum:94291069FEAD59A3925D18650B13BF250328D9065001C7FBF81756B046F5F8C8;SizeAsReceived:7262;Count:47 x-ms-exchange-messagesentrepresentingtype: 1 x-tmn: [8XHGyflJ0h9KsoKU0EHgatu6evSb+Zu0] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1;CO1NAM05HT187;7:76KhlKSo5/eIcEhd0pduYDXiP9SjF2t5Q119HaAzCuA+dUcETUKYKn6FPGpb9D0sWs5cZd0VzWI2lO4kFLdG1+ppKxH+PgVN7dMXJFj6IwH7i2kbrDoAmkZEtcja5ZKXcqMLvBvFfmz06+YljPwMpZ+1wBPbCHerGJkvwjNFIklwvOJ41KFd+oBw8GnNmV0CAYHap2lKWpSXtdMQwTGjvRNuwEWfnWG0s/SfRrZclycqg87/s+mo2cRTpgnpEdXj x-incomingheadercount: 47 x-eopattributedmessage: 0 x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(201702061078)(5061506573)(5061507331)(1603103135)(2017031320274)(2017031324274)(2017031323274)(2017031322404)(1601125500)(1603101448)(1701031045);SRVR:CO1NAM05HT187; x-ms-traffictypediagnostic: CO1NAM05HT187: x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(444000031);SRVR:CO1NAM05HT187;BCL:0;PCL:0;RULEID:;SRVR:CO1NAM05HT187; x-forefront-prvs: 0704670F76 x-forefront-antispam-report: SFV:NSPM;SFS:(7070007)(199004)(189003)(305945005)(5660300001)(426003)(229853002)(20460500001)(55016002)(6306002)(33656002)(486006)(2900100001)(74316002)(11346002)(476003)(446003)(5250100002)(6346003)(102836004)(25786009)(82202002)(26005)(87572001)(6436002)(81156014)(110136005)(68736007)(86362001)(8676002)(14454004)(6246003)(53546011)(97736004)(105586002)(8936002)(39060400002)(4326008)(966005)(104016004)(99286004)(106356001)(3280700002)(76176011)(7696005)(3660700001);DIR:OUT;SFP:1901;SCL:1;SRVR:CO1NAM05HT187;H:CY4PR18MB1048.namprd18.prod.outlook.com;FPR:;SPF:None;PTR:InfoNoRecords;A:1;MX:1;LANG:; received-spf: None (protection.outlook.com: outlook.com does not designate permitted sender hosts) authentication-results: spf=none (sender IP is ) smtp.mailfrom=theodorejb@outlook.com; x-microsoft-antispam-message-info: PfobWGYxpz/C/1iRIaro1TWnye9Siapscjs9LQEgo+uuQrPiilJXYR25YsoPtdma0W/2nJU4IYeG9qFiz99J2KLdaSDqU9vIsXT+vH4tY7/DgD3E9IhvvT4+YKHALjbycwn2FQTbR69b+B0kC0r2T+5UZRKNyk/F3WREKkEbhXpgnrV2sdNP51qk88jSvA5H Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: dd759f05-a917-4aa0-a2f5-4cc35c50e0c8 X-MS-Exchange-CrossTenant-Network-Message-Id: 48c75cd6-d7fd-48de-387a-08d5d2cff128 X-MS-Exchange-CrossTenant-rms-persistedconsumerorg: dd759f05-a917-4aa0-a2f5-4cc35c50e0c8 X-MS-Exchange-CrossTenant-originalarrivaltime: 15 Jun 2018 14:54:48.8176 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Internet X-MS-Exchange-CrossTenant-id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO1NAM05HT187 Subject: Re: [PHP-DEV] Strict switch statements From: theodorejb@outlook.com (Theodore Brown) On Thu, Jun 14, 2018 at 4:35 AM, Nikita Popov wrote:= =0A= =0A= > I think if people want to use strict matching, they'll quite likely want = to=0A= > have it on all cases. Something like "strict switch ($expr) {}" or "switc= h=0A= > strict ($expr) {}" or "switch (strict $expr) {}" or "switch ($expr) stric= t=0A= > {}" or "switch ($expr) { strict; }" or whatever would be preferable in th= at=0A= > case.=0A= >=0A= > Additionally, switch has the issue of fall-through behavior, which is=0A= > somewhat unexpected and error prone to many people. It might make sense t= o=0A= > introduce an entirely new "match" statement that conforms a bit more with= =0A= > how switch-like strictures are implemented nowadays. That is, something l= ike=0A= >=0A= > match ($expr) {=0A= >=A0=A0=A0=A0 "foo" =3D> {...},=0A= >=A0=A0=A0=A0 "bar" | "baz" =3D> {...},=0A= > }=0A= >=0A= > or similar. This might need some more design work to ensure forward=0A= > compatibility with potential future algebraic datatypes etc.=0A= =0A= I really like this idea. It's similar to the `match` control flow operator= =0A= in Rust: https://doc.rust-lang.org/book/second-edition/ch06-02-match.html.= =0A= =0A= One reason I almost never use the `switch` statement in PHP (besides the=0A= lack of strict matching) is that it's so verbose. Having to put a `break`= =0A= keyword after every case to avoid fallthrough means that it almost always= =0A= requires less code to use `if` statements instead.=0A= =0A= To avoid confusion with union types, I think I would prefer commas between= =0A= or conditions instead of a pipe character. Example:=0A= =0A= ```=0A= match ($expr) {=0A= "foo", "bar" =3D> {echo 'expr is "foo" or "bar"';},=0A= true =3D> {echo 'expr is true';},=0A= 1 =3D> {echo 'expr is 1';},=0A= null =3D> {echo 'expr is null';},=0A= false =3D> {echo 'expr is false';},=0A= default =3D> {echo 'expr is something else';},=0A= }=0A= ```=