Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:109436 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 3654 invoked from network); 29 Mar 2020 23:42:20 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 29 Mar 2020 23:42:20 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 51FDB1804C4 for ; Sun, 29 Mar 2020 15:08:06 -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,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-yb1-f182.google.com (mail-yb1-f182.google.com [209.85.219.182]) (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 ; Sun, 29 Mar 2020 15:08:05 -0700 (PDT) Received: by mail-yb1-f182.google.com with SMTP id t10so449152ybk.8 for ; Sun, 29 Mar 2020 15:08:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=E70YIJrEhcpklbNaMlsjqd45D1IdYh+ZBhW3UwC93ck=; b=RdPIL622xOxMND++9tydXYKCHFJIen0yn7F9oHVxs+8W2Xfeh1MhJ5+9QhZGIBr4c6 upATBeXjN2gB3Smn+yw1cH+OdxZGSs/g8Urjn7dTa/Fy1BsAEFnKPBLkSoKCOPYx0sHm PdgDvRIKs4no96LNoQIAwIu+A3ebxYyhH36eTmXJy/RFu9OaNuVFpAKBBNRidL91AJrG YWtFOJqLC8laBHJ8KqohG294jkExdlgushOaFyjcauPFwBLU4JdvcnpadAflOWsricK2 B6e2QKEhIjkMbYqGaqKiKI6x0lRZ5iMF4HD1sAygadAs57sitQs7JqvSQn17VD+hAvZj b1Kg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=E70YIJrEhcpklbNaMlsjqd45D1IdYh+ZBhW3UwC93ck=; b=knt7nL3/FiLjTCyfqguOHH0wx2j0paosTW14WjAu3tXcA79GoA0yNaiekOf4CJ0OIe n5F7rDMHVFaYpYAiNL4omyHaCPXEcBAJ4hey22AxGJadS+GBAmibSK/UQvW6kty4my4g InZ9Di+HoGlxB7PbOTFAddUktTlkZbeB641vFX6Ec+WfiTNpZ4NZscRhSXZFANI30Oby 6ngCchCm09AVMOaPGD/vciskiWtt3fHqmUk4r7l089rXxJK6TYLicJQuB+Irux+rBHBD nXV/haFe7luCjJj+ctxuNQePz4H3CcwMWEW0TZaM753bSDSpwsDbTA9WVdcvNfcEpYrg Gn/w== X-Gm-Message-State: ANhLgQ1hrxsTZ2ktJ31c8iXrDYYgmqyZpBJ8FB0gBwWjpEZ4JrtMk6g0 1Doiw6y0enYADL1iBKOhi2wlvr4KK0pY+OGYaoYluj+s X-Google-Smtp-Source: ADFU+vvmZ0jJwszQXuM2uULajVFlSZZP7wnNDXUyyb4J3dkjLnvxt8fW39nafejYDjMpdHj6hJDJKWyRKCEh42Le+wI= X-Received: by 2002:a25:8110:: with SMTP id o16mr15503869ybk.347.1585519683762; Sun, 29 Mar 2020 15:08:03 -0700 (PDT) MIME-Version: 1.0 References: <047092C7-84FB-42AB-8084-7B83F76F55C1@me.com> <026AF97E-ED0C-411C-8942-7DA7CC9705DB@me.com> <34ce624e-7d00-4f63-2c4f-da125deb65b8@gmail.com> In-Reply-To: Date: Mon, 30 Mar 2020 00:07:52 +0200 Message-ID: To: Larry Garfield , PHP internals Content-Type: text/plain; charset="UTF-8" Subject: Re: [PHP-DEV] [RFC] switch expression From: tovilo.ilija@gmail.com (Ilija Tovilo) Hi Larry Thanks for your suggestion. I chose to use switch instead of match for a couple of reasons: 1. It uses the same AST, code generation and opcodes as the switch, I don't agree that it is significantly different than the switch that we already have. 2. Adding the `match` keyword is a breaking change, not an insignificant one. 3. If we can fix the switch statement semantics in the future the two will only differ in that one returns a value and the other one doesn't. This is a much smaller distinction than functions/closure. 4. If we'd every want to add pattern matching, we'd still have a keyword available to us. > I don't believe that's the case here, however. `switch` is a language construct for a *statement*, which branches the flow of control of the program. > > What you're proposing is a language construct for an *expression*, which evaluates depending on internal logic to a different value. Well, I encourage you to look at the implementation. You'll see that the two are in fact very similar. I'm not averse to using the match keyword if people are ok with the BC change. If we do though we definitely should make it work as a statement, allow blocks in addition to single expression and also fix type coercion. This would make it a replacement of the switch statement instead of an addition. Ilija