Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:107555 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 13920 invoked from network); 16 Oct 2019 10:10:22 -0000 Received: from unknown (HELO php-smtp3.php.net) (208.43.231.12) by pb1.pair.com with SMTP; 16 Oct 2019 10:10:22 -0000 Received: from php-smtp3.php.net (localhost [127.0.0.1]) by php-smtp3.php.net (Postfix) with ESMTP id A22162C1ADF for ; Wed, 16 Oct 2019 00:54:41 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp3.php.net X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,HTML_MESSAGE,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS3215 2.6.0.0/16 X-Spam-Virus: No Received: from mail-ot1-x32b.google.com (mail-ot1-x32b.google.com [IPv6:2607:f8b0:4864:20::32b]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by php-smtp3.php.net (Postfix) with ESMTPS for ; Wed, 16 Oct 2019 00:54:41 -0700 (PDT) Received: by mail-ot1-x32b.google.com with SMTP id y39so19323561ota.7 for ; Wed, 16 Oct 2019 00:54:41 -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 :cc; bh=iKmoLh9nVqWIysyYdn22BZz0uQMot9m+1E98WENZqWs=; b=pTokWuNeyqVCJCLNsoUOnYpeNSJD951uAOoLHxhCGI8IQrddjOk6JJ6EQzUiAJvFHM R7rZSndAcKTtJACdM2pT51cUvuCJsZfEc1iHBfbEAk2Df0MKAnAeOJKp/QEjjphjKeL5 8YgSscYzrOtZTDVJqE2bM4MZujk9zfE1V295DgNEGguEbv7S9a79LXyK6fX7ePtKOrrD lyJgisnf0Sn5wNEG7TJZeaeasIIepZfspxje5PnzwjQ3yYlE/IKm+d2ZUcTU0LHdDicG nxqUSTfuiVx9Wyhf1ooW0rqK9Au//TEErFHY8A+aLjEY0CbILIDNZSKra0/GMI3zyxs+ /OcA== 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:cc; bh=iKmoLh9nVqWIysyYdn22BZz0uQMot9m+1E98WENZqWs=; b=kIfCsclr5oZ9Dat1Y3NZtKvhG7aqw/c01BJcKIb57OipG4Q7r95wWrZ6BlXLUbRYdV DM6sEgyHLf81jJbUQJuPxxrOFw+eqt+JHtC0zVyQDRxJIxe6RMx1hU/cbVNNdcN51pqL VaL8hknAb66YLt3kXY7wC8GGuNmo1gIlgBw5hqsCw3MEeuMZp0eYsjCNZBc1ExRywU8W jpbHrIJ0mlHyDING/aaAE16NN3+pLQndMcdCqNPQLA5VnE/K5DBG9Fvzgfl+fUVRDV5i yOUB0QoPYy0HlLzPpurdig8tYMKOYcOoxR6XVXglMkVJ2LMPxdO3kVZSanG5Br3Rl1Tq V6Kw== X-Gm-Message-State: APjAAAXcp9Sraqz9TmNzPv/8bFMA5flo5Zs2VcCY8bXIWcIWW2s1xeuD 8fh8qf/QMEB2+KEsh37UehUwLcTyXlh3KWSg6Og= X-Google-Smtp-Source: APXvYqwQuLp8q4Jn55HsfUAfh3o7NwlW1JpNuwPPU6eXiQbzUgMqtrFPv/f3yrcYV4bqIsmB1+fv7WPs/+OAs4YlZ24= X-Received: by 2002:a05:6830:16c8:: with SMTP id l8mr9356921otr.214.1571212480418; Wed, 16 Oct 2019 00:54:40 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Wed, 16 Oct 2019 09:54:27 +0200 Message-ID: To: Kosit Supanyo Cc: PHP Internals List Content-Type: multipart/alternative; boundary="000000000000c319b40595026952" X-Envelope-From: Subject: Re: [PHP-DEV] Inline switch as alternative to nested inline conditional From: michal.brzuchalski@gmail.com (=?UTF-8?Q?Micha=C5=82_Brzuchalski?=) --000000000000c319b40595026952 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi Kosit, =C5=9Br., 16 pa=C5=BA 2019 o 09:41 Kosit Supanyo n= apisa=C5=82(a): > Hi Michal > > I'had the idea similar to your RFC but instead of using `switch` keyword = I > think introducing `when` keyword is better. (as I know a language that us= es > this keyword is Kotlin) > > $result =3D when ($v) { > 'foo' =3D> 1, > 'bar' =3D> 2, > 'x', 'y', 'z' =3D> 3, > default =3D> null, > }; > > Above you can see that `when` syntax is more semantic than `switch`. And > it is easier to implement in parser because it has no statement/expressio= n > ambiguity. > > But this might not be preferred by BC camps because introducing a new > keyword might break BC. > And if `switch` is chosen I still think the syntax should be comma > separated instead of semicolon separated for consistency with other list > expressions (array/function call). > > $result =3D switch ($v) { > case 'foo' =3D> 1, > case 'bar' =3D> 2, > case 'x', 'y', 'x' =3D> 3, > default =3D> null, > }; > That's exactly my proposal with commas, see here: https://wiki.php.net/rfc/switch-expression-and-statement-improvement#switch= _expression_introduction Unfortunately, this RFC needs more work cause it mixes switch statement enhancement with comma-separated list syntax and of switch statement - I need to split it into two RFC's This is nice hearing that this idea has an interest. As soon as the RFC will be split and finished I can start a discussion thread. Cheers, Micha=C5=82 Brzuchalski --000000000000c319b40595026952--