Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:107556 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 21541 invoked from network); 16 Oct 2019 10:53:05 -0000 Received: from unknown (HELO php-smtp3.php.net) (208.43.231.12) by pb1.pair.com with SMTP; 16 Oct 2019 10:53:05 -0000 Received: from php-smtp3.php.net (localhost [127.0.0.1]) by php-smtp3.php.net (Postfix) with ESMTP id 5BD412D202D for ; Wed, 16 Oct 2019 01:37:27 -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-oi1-x235.google.com (mail-oi1-x235.google.com [IPv6:2607:f8b0:4864:20::235]) (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 01:37:26 -0700 (PDT) Received: by mail-oi1-x235.google.com with SMTP id k9so19339586oib.7 for ; Wed, 16 Oct 2019 01:37:26 -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=CfkoGqWSfvLHYCKhDCVvKyDEQtITohwURhnUNYs8Nxc=; b=Yg6qcKwZXhXKKUVlSWxap4DUtr5c3gWoxuy5bUyX0d33RTz2A/DLByAfkEVYXdi9vs Bqrx1Kew14qo5hjHB+Awg3VxyrRw/u9QqySJrZBQYL5QnpD2h/utAh84rZR+LBVRz0bH tRt6ml0XufFTJWoTW6UMG1uq+rWR8ZWgpHcNYTCe17xPPjSrFA3EDBMl3lT8y3BLF+hL 3A3MB//isCthyWMRIDwlkr7MB11IUViTDN0QURIPs5RtYqPdBNlIBoyGjBqOtDvBR1OZ c4YekuxdzRgSKJIAusvRae91bLUCRREJm0idUdLQzErOMLcfZVHYOhvcjvV3L92ccZpk Kiwg== 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=CfkoGqWSfvLHYCKhDCVvKyDEQtITohwURhnUNYs8Nxc=; b=VbkMsRvQ3+UXh6OFcnJHPxy0vadXqff1K1jSoNCeWMSx/xMzkYZJxm3nF3rQLExq5v FRKC9ZHhu+O2KoKMyxpCKQ71Va37SdnYGiJEdmYa/H/mhuW/5iilr9UFES78hezl8WEC 0rKaM0FrRDGOPmiRAF4qxbcKkpZrFagmiNVE+mLOUnuuMJeFZv1Qz8BBO/GpTGL03D5w /B7m3LFafDrr/4NnpxS+/vbPq0CAR5y6x+VdqOSGAsJ552CsCiW/fWqWFq3nxV86r1HE zAwoS/RZIHMESymqkCnC8sAh9kL8MOo9SBSuPzNFtG6MVkFlu8+LgPap/eYD6jLgNPp2 o8cQ== X-Gm-Message-State: APjAAAVGRu+jI6nCm2OOFeTdOJ0kiw114b4/kTQWTDFzXGYzOf0MsZJW SZVV2Rn1bauSKzd+XjCn7s1Dh7y7XNE7wfU+3pQ= X-Google-Smtp-Source: APXvYqxefg7zBEdR3hL/SFbwcPNLTfDpB6cN3PTtOSgHVjHbQQ72N+3UFtL8lqZycn6MBt4LYxy3X4TyomgCltoMf4A= X-Received: by 2002:aca:cd4d:: with SMTP id d74mr2465208oig.157.1571215046078; Wed, 16 Oct 2019 01:37:26 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Wed, 16 Oct 2019 15:37:13 +0700 Message-ID: To: =?UTF-8?Q?Micha=C5=82_Brzuchalski?= Cc: PHP Internals List Content-Type: multipart/alternative; boundary="000000000000aff5f205950302e4" X-Envelope-From: Subject: Re: [PHP-DEV] Inline switch as alternative to nested inline conditional From: webdevxp.com@gmail.com (Kosit Supanyo) --000000000000aff5f205950302e4 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable I mean separation between cases not case conditions. Examples in your RFC uses semicolon as case separator instead of comma. "weekend!"; case 1, 2, 3, 4, 5 =3D> "weekday :("; case 6 =3D> "weekend!"; }; echo "Today is {$say}"; I prefer comma because semicolon should only be used to separate statements but switch expression is list of condition/expression pairs not statements. So it should be: "weekend!", case 1, 2, 3, 4, 5 =3D> "weekday :(", case 6 =3D> "weekend!", }; echo "Today is {$say}"; You may think t's fine because Java uses semicolon but IMO Java had made a mistake. (C# is semantically correct) Cheers On Wed, Oct 16, 2019 at 2:54 PM Micha=C5=82 Brzuchalski < michal.brzuchalski@gmail.com> wrote: > Hi Kosit, > > =C5=9Br., 16 pa=C5=BA 2019 o 09:41 Kosit Supanyo > napisa=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 >> 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/expressi= on >> 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#swit= ch_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 > --000000000000aff5f205950302e4--