Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:107554 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 10394 invoked from network); 16 Oct 2019 09:56:55 -0000 Received: from unknown (HELO php-smtp3.php.net) (208.43.231.12) by pb1.pair.com with SMTP; 16 Oct 2019 09:56:55 -0000 Received: from php-smtp3.php.net (localhost [127.0.0.1]) by php-smtp3.php.net (Postfix) with ESMTP id E8A772D203B for ; Wed, 16 Oct 2019 00:41:15 -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=-1.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,FREEMAIL_REPLY,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-oi1-x229.google.com (mail-oi1-x229.google.com [IPv6:2607:f8b0:4864:20::229]) (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:41:15 -0700 (PDT) Received: by mail-oi1-x229.google.com with SMTP id x3so19217522oig.2 for ; Wed, 16 Oct 2019 00:41:15 -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=tx5OR5G71tNOxO8zYkLTq/mGRxZyccyknvYryAe9m18=; b=nW4ZjQksBF7kDqMCfyHCwwWhdaxOsJRaseWiPclDfYkKG1clieEVlBCaEwQBcER38q G7jUHml4wTdMGt7IkN5RU04bTl85kRdL0grKuwgozLdhRXUXNFgl9yS0DliFz/iYCvIQ vosVwPRpHCSEsYZuHmQfwFMfL70TV6RIS/EBvMYfnm7Rl1supKsiJH/lqa0k1RGlhzHU BWKH+BgY2TNPSPTxNCwccPty9lcJX1OrXPBRbOIo9mbqBhQaYXpIaVed+kwRRtelxk+b uJJABar5tuDyhcMvXqGMpaYiIwS4w7UA4l4Wa3c9Qu5c3sAb1rGHb49ep0W6EnFtSrrt YOZA== 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=tx5OR5G71tNOxO8zYkLTq/mGRxZyccyknvYryAe9m18=; b=Qtw7UgfPWB1Izl/omQKKDL04OJeVVrAJ1RcFE+a9hcr7A0mdAOUOfh2nkRx9gCkLjm gFTGzZqEOG35XjRwAOcBYRyn/N0ZOz0tc0VDwaX3dP496Z0vkS7nFTNOlc6Zvh/ZMBC/ XKZWjK2ebigkIbQ6hN2rLZYGDGbEisv2RXqrp+iX9COTkCSlyeLhURtyeeMbvaMUz234 F2p+h56JB0WDS2W1bEuK5NnIBcsaEv7mOYg8Lu6J/2yUJhN45GK0GuZz1CuNjcJpjJpu phZ3OcxlpxyI00BSFiYExX8MqyC7ANDTdBZtk5CKAvNKmG0feBGlem1gibF+6Sr1Q6n0 iYbA== X-Gm-Message-State: APjAAAVCrTnpakx4/8ErPuxdIfJLydIWnvpgV/DdLpJCwPeD/ugeXCEZ vVrmLkHt3i2h22pybHaTxi6csgdiggK06ppruZM= X-Google-Smtp-Source: APXvYqwdPZ3uodkJAnD4aWoBtE03JgnqZPVCQcf98XA1WIuAY8c9If49i9XPMf+LF7ukSOTpIr7Jmb6884KbtKH595w= X-Received: by 2002:aca:c3c6:: with SMTP id t189mr2150661oif.15.1571211674743; Wed, 16 Oct 2019 00:41:14 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Wed, 16 Oct 2019 14:41:02 +0700 Message-ID: To: =?UTF-8?Q?Micha=C5=82_Brzuchalski?= Cc: PHP Internals List Content-Type: multipart/alternative; boundary="000000000000bd776105950239dd" X-Envelope-From: Subject: Re: [PHP-DEV] Inline switch as alternative to nested inline conditional From: webdevxp.com@gmail.com (Kosit Supanyo) --000000000000bd776105950239dd Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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 uses 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/expression 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, }; Cheers On Wed, Oct 16, 2019 at 10:33 AM Micha=C5=82 Brzuchalski < michal.brzuchalski@gmail.com> wrote: > Hi David, > > I'm interested in this feature this is called switch expression and is on > my list of RFC to process after Object Initializer RFC. > > I have an RFC in draft for that and planning to finish it soon together > with some syntax optimisations - you can see it at > https://wiki.php.net/rfc/switch-expression-and-statement-improvement > > Cheers, > Micha=C5=82 Brzuchalski > > =C5=9Br., 16 pa=C5=BA 2019, 03:46 u=C5=BCytkownik David Rodrigues > > napisa=C5=82: > > > Hello. I like to suggests a discussion about a FR to make possible to > > inline switch, as an alternative to nested inline conditionals. > > > > $value =3D switch (expr()) { > > case A1: return A2; > > case B1: return B2; > > default: return C; > > } > > > > Instead of: > > > > $expr =3D expr(); > > $value =3D $expr =3D=3D A1 ? A2 : ( $expr =3D=3D B1 ? B2 : C ); > > > > Just a discussion to check what do you think. > > > > -- > > David Rodrigues > > > --000000000000bd776105950239dd--