Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:102255 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 77271 invoked from network); 14 Jun 2018 09:57:29 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 14 Jun 2018 09:57:29 -0000 Authentication-Results: pb1.pair.com smtp.mail=php-lists@koalephant.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=php-lists@koalephant.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain koalephant.com designates 206.123.115.54 as permitted sender) X-PHP-List-Original-Sender: php-lists@koalephant.com X-Host-Fingerprint: 206.123.115.54 mail1.25mail.st Received: from [206.123.115.54] ([206.123.115.54:43114] helo=mail1.25mail.st) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 9A/29-29356-90C322B5 for ; Thu, 14 Jun 2018 05:57:29 -0400 Received: from [10.228.245.47] (ppp-223-24-184-2.revip6.asianet.co.th [223.24.184.2]) by mail1.25mail.st (Postfix) with ESMTPSA id A26E460533; Thu, 14 Jun 2018 09:57:20 +0000 (UTC) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (1.0) X-Mailer: iPhone Mail (15F79) In-Reply-To: Date: Thu, 14 Jun 2018 16:57:17 +0700 Cc: Sara Golemon , PHP internals Content-Transfer-Encoding: quoted-printable Message-ID: <22667B60-EA84-4095-90ED-F8E4CDDA8285@koalephant.com> References: To: Nikita Popov Subject: Re: [PHP-DEV] Strict switch statements From: php-lists@koalephant.com (Stephen Reay) Apologies - sending again from on-list address.=20 I=E2=80=99m not overly fond of the `case =3D=3D=3D` Could it be simply `case` for current behaviour and `strict case` for the ne= w behaviour?=20 I=E2=80=99d argue that while fall through can cause problems it also has leg= itimate uses. Sent from my iPhone Sent from my iPhone >> On 14 Jun 2018, at 15:35, Nikita Popov wrote: >>=20 >> On Thu, Jun 14, 2018 at 6:53 AM, Sara Golemon wrote: >>=20 >> Just for casual discussion at this point: >> https://github.com/php/php-src/pull/3297 >>=20 >> switch ($a) { >> case FOO: >> // Works exactly as current behavior. >> break; >> case =3D=3D FOO: >> // Nearly identical, though not using the ZEND_CASE optimization. >> // Can probably make this equivalent to `case FOO`, but it felt >> like an interesting direction. >> break; >> case =3D=3D=3D FOO: >> // Only triggers if `$a =3D=3D=3D FOO`, no type juggling >> break; >> } >>=20 >> Love it? Hate it? See obvious flaws? The implementation is just a >> rushed proof of concept, not something I've labored over, it may well >> have bugs. Certainly wouldn't target anything earlier than 7.4, if at >> all. >=20 > I like the general idea here (switch with strict type comparison), but not= > super fond of the particular syntax and implementation. >=20 > I think if people want to use strict matching, they'll quite likely want t= o > have it on all cases. Something like "strict switch ($expr) {}" or "switch= > strict ($expr) {}" or "switch (strict $expr) {}" or "switch ($expr) strict= > {}" or "switch ($expr) { strict; }" or whatever would be preferable in tha= t > case. >=20 > Additionally, switch has the issue of fall-through behavior, which is > somewhat unexpected and error prone to many people. It might make sense to= > introduce an entirely new "match" statement that conforms a bit more with > how switch-like strictures are implemented nowadays. That is, something li= ke >=20 > match ($expr) { > "foo" =3D> {...}, > "bar" | "baz" =3D> {...}, > } >=20 > or similar. This might need some more design work to ensure forward > compatibility with potential future algebraic datatypes etc. >=20 > Nikita