Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:109932 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 47864 invoked from network); 29 Apr 2020 18:48:53 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 29 Apr 2020 18:48:53 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id ADA401804CA for ; Wed, 29 Apr 2020 10:22:22 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS15169 209.85.128.0/17 X-Spam-Virus: No X-Envelope-From: Received: from mail-wr1-f54.google.com (mail-wr1-f54.google.com [209.85.221.54]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Wed, 29 Apr 2020 10:22:22 -0700 (PDT) Received: by mail-wr1-f54.google.com with SMTP id d15so3529935wrx.3 for ; Wed, 29 Apr 2020 10:22:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-transfer-encoding:content-language; bh=EVjuug2AnHx+LzxXgFG97PhmeOj1iNk66Dx2XqyL4bg=; b=ObQr8GVmmP01JMW/7e9TmlLokBVP7jnhwGGz4GaJbvFYBiZRxdsUFQrhWLuw8cZbyG HlNn2BtkPLvV4Bb5ml44fHReRkUPWt8gHHVUmO6HTUay1TVYWV2FX9x4DzR7WWugY/5O lIUqDllCwx56Yqu4EyaAjhy7jyn7b8FoqhMq3G5Nb3K5BSpilXk0FWKtCgdGnvkbFDIO 3QC2dkE1ObvYPsVBT5uxTtNJXE688KySMZTenK3pvUoM0nYPER+Oba0IVZQswZTEigb0 BgRvIjL/G8XuZQq/u+s7A6SUPwS3mxomno7NOORvZds6DoaVolGwqTuAG4UuIoLWYDwy /vPg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=EVjuug2AnHx+LzxXgFG97PhmeOj1iNk66Dx2XqyL4bg=; b=cac1wfcD0rt0KbwZ91TGgFzmYzkKo+GwLTgvbsm+qXxdC1hzcmUiUNrxKs9IGfe1oH JWZmDMyXLmc7XB82tUEnSNWqmQ951RNRcQHeRPAul95Vjz8VqCaVWOGpQXH8xZMOJGog C9331RY5gW6LqLa+gvz5CSVL3VOnYNYDYA1fIPMRYTLsUVjWfJoawVHsZLIrLC47DjH/ IFQ8kQuWm1k6fFrde3qzIUBK2MqQSuF+3IHlYwvOKauxFM1KVQ16ngGsJkXzsQk0ghjN MVujNBAaD+5nARdx+Vb8p3NNs2y8VNaOvK4AQ01VU978zdOtmnIEYCRzpbOzDdfYNE7j gLwA== X-Gm-Message-State: AGi0PuZuCNKkvOEP/u6zOQAZRPbHS/+7+BOkj7tm2Q69jZ4vmOyvYAfa hAS7jXPoPyL7VSrJMCoHjoyi46tb X-Google-Smtp-Source: APiQypJ3qBKqNjorJDmmMhO/s+jSlZ47hkvYAa3+CGDgDVbACcVsn4Lp7H8rnJJT/AwsphXwL5Aqjw== X-Received: by 2002:a5d:6850:: with SMTP id o16mr39178787wrw.309.1588180938936; Wed, 29 Apr 2020 10:22:18 -0700 (PDT) Received: from [192.168.0.14] (cpc84253-brig22-2-0-cust114.3-3.cable.virginm.net. [81.108.141.115]) by smtp.googlemail.com with ESMTPSA id c10sm29422778wru.48.2020.04.29.10.22.18 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 29 Apr 2020 10:22:18 -0700 (PDT) To: internals@lists.php.net References: <5ea6e4b0.1c69fb81.cf3ee.2bbfSMTPIN_ADDED_MISSING@mx.google.com> <969c6150-a084-48c0-ae8f-b8043dce321d@www.fastmail.com> Message-ID: <6f55fbce-904b-910f-35d1-c6d91504d01f@gmail.com> Date: Wed, 29 Apr 2020 18:22:17 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.7.0 MIME-Version: 1.0 In-Reply-To: <969c6150-a084-48c0-ae8f-b8043dce321d@www.fastmail.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-GB Subject: Re: [PHP-DEV] [VOTE] match expression From: rowan.collins@gmail.com (Rowan Tommins) On 29/04/2020 01:26, Larry Garfield wrote: > To that end, I'm going to refer to them as rustmatch (an expression that only supports expressions and returns things; basically a fancier alternative to ternary) and switchtng (a procedural branching statement that is basically switch but with the lessons of the 40 years since C switch was invented, which PHP blindly inherited) to avoid privileging one or the other. I like the codenames. :) Thinking about it, I think the "switchng" syntax can be even more conservative. The RFC lists four issues with switch, of which three would be applicable to a "switchng" RFC: 1. Type coercion 2. Fallthrough 3. Inexhaustiveness For #1, the only thing we need is some way to opt into "strict mode" on the switch statement, and have the comparisons handled by === rather than ==. That could be as simple as writing "switch strict" instead of "switch". For #2, the problem is that fallthrough is implicit where no "break" is present, so what if we just said that reaching another "case" statement was a runtime error in a switchng statement? That would mean any existing switch statement that didn't use fallthrough could be "upgraded" without changing its body at all. We could allow multiple case labels with no statements between, allowing for the common scenario of multiple conditions running identical code. Alternatively (or as a separate enhancement) we could allow comma-separated lists in case blocks (on both normal switch and switchng). For other cases of fallthrough, we could add a new keyword (or recycle "continue") to explicitly go to the next case. That could even be left to "Future Scope", because anyone wanting it can always "downgrade" to the version with implicit fallthrough. Finally, #3 can be part of the same "strict mode", with one of two behaviours: a) Make a switchng with no "default:" clause a compile-time error b) Make a switchng which doesn't match any case a run-time error, effectively adding an implicit clause of "default: throw new Error(); break;" So our shiny new "switchng" statement would look ... exactly the same as a normal switch statement, but with one new keyword, and the ability to throw two new errors. Regards, -- Rowan Tommins (né Collins) [IMSoP]