Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:102256 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 83473 invoked from network); 14 Jun 2018 11:32:05 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 14 Jun 2018 11:32:05 -0000 Authentication-Results: pb1.pair.com smtp.mail=cmbecker69@gmx.de; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=cmbecker69@gmx.de; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmx.de designates 212.227.15.15 as permitted sender) X-PHP-List-Original-Sender: cmbecker69@gmx.de X-Host-Fingerprint: 212.227.15.15 mout.gmx.net Received: from [212.227.15.15] ([212.227.15.15:43625] helo=mout.gmx.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 76/D9-29356-432522B5 for ; Thu, 14 Jun 2018 07:32:04 -0400 Received: from [192.168.2.114] ([79.222.35.93]) by mail.gmx.com (mrgmx003 [212.227.17.190]) with ESMTPSA (Nemesis) id 0MPm54-1fXFxq2hUo-0052VL; Thu, 14 Jun 2018 13:32:00 +0200 To: Nikita Popov , Sara Golemon Cc: PHP internals References: Message-ID: <9a57d134-ba56-1784-a76a-e914fd348e01@gmx.de> Date: Thu, 14 Jun 2018 13:32:01 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.8.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: de-DE Content-Transfer-Encoding: 8bit X-Provags-ID: V03:K1:NLuezb6Y0G46jv2zBnbKxavoil2kZPiDV3awaxelIXNVo3/BLAU 45nV+YunyQQ5OVwdJBdAqCiszYhIZxvVFnjLWMr3NZX5WzHWfUcLvAhC6Oahkss2ORk7cOK KgfOdD92gma/k76qPKyZ8RA0V+zBMqxtzfUaZsHg3CLeNWbUtepwBhZlTvq98uDAKfJkMz1 cj9jWJnIAPkqnHGrmA9Ug== X-UI-Out-Filterresults: notjunk:1;V01:K0:cy9u7qHUDm0=:Z4UoYHvyTngBWi5zZE9QUH ZKeuodAd7bMsHxchPXEk6wBFStinrrLto4rATh7TDIeTQ+petmuDEK+sv1AHYdnnVjSClJ/ah sxcJRAgJ+hvVI2tLfIYANrNKKFS7Q19SohTXTyrpyLrs5SNaxoo+SkBVdoVtmvltKslGcpHUQ /+wFO5drLHfyo7OrFJ7MS4NC55nV7GR9x1+J6UeGWUVrzSw4MfRlWr7y9EtJX8Y23qDFK9mY5 IyOnY+K28z2v6PIEZRakYj82/wRLyeQA431LRxch47jfBZmKZ2XS5P1BzO3caFFRBYSCmdRVh fdMIG89aXW5gxsqR8ISTTh1EsaPC/oFXclOQLowlywtHCMzj8pgkHC4zhchDadv639s5WWcX0 cM/lYliA2bnZ8YGTRboptLp6mlXp2GjRi3nnG+AJ01L65MtBthIaJ5OZaGqalNXbjuhOJEaw4 hQhpsXX4BKc63LLJQP68wRBfn3O3nf8pVfMrDmpYUEoHcMkhlznzGZDfXJ++0H9YKV6aoXoFH 09ydYfl/VGalQ71JIr8Hi0pm4NMqVQp/32Rsfcbw7avf/f7Swp1GchAL+7Yg18OetPymJhjui hdgpC+x7tQCQhMbSZ70VEbOqIz0PNPqlbjYKkes/cLul9xkgxwWQC9kx0Md3LtXdm6pTi5MQ6 KNUVg4MpOuEmg+I8YiM4Lotzr4Sn/qNtqUhNqpTf612K4Ep0RDvYyyGf3f5uaJJ3zuQLlrvaq GQrlafg2/dHl7Jx5i2P6P+i8caXhOQuGEMyeLuBX7DB+DgNW+z5/dfpON3dVviNxC+sUxwHNw FFm17dA Subject: Re: [PHP-DEV] Strict switch statements From: cmbecker69@gmx.de ("Christoph M. Becker") On 14.06.2018 at 10:35, Nikita Popov wrote: > On Thu, Jun 14, 2018 at 6:53 AM, Sara Golemon wrote: > >> Just for casual discussion at this point: >> https://github.com/php/php-src/pull/3297 >> >> switch ($a) { >> case FOO: >> // Works exactly as current behavior. >> break; >> case == 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 === FOO: >> // Only triggers if `$a === FOO`, no type juggling >> break; >> } > > I like the general idea here (switch with strict type comparison), but not > super fond of the particular syntax and implementation. > > I think if people want to use strict matching, they'll quite likely want to > have it on all cases. […] ACK. Even the example shows the gotchas with this kind of mix: the final case would never match, or would it (which I would find even more confusing)? Furthermore, I personally don't like switch statements in a higher level programming language, since they feel so low level (optional fall through, and whatever). And there is already the “switch (true)” hack, to make the proposed behavior possible (without optimizations, though, I presume), see and . > 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 like > > match ($expr) { > "foo" => {...}, > "bar" | "baz" => {...}, > } On a quick thought, I like this! -- Christoph M. Becker