Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:107621 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 72642 invoked from network); 22 Oct 2019 00:38:11 -0000 Received: from unknown (HELO php-smtp3.php.net) (208.43.231.12) by pb1.pair.com with SMTP; 22 Oct 2019 00:38:11 -0000 Received: from php-smtp3.php.net (localhost [127.0.0.1]) by php-smtp3.php.net (Postfix) with ESMTP id 78D5C2C050B for ; Mon, 21 Oct 2019 15:23:55 -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-x336.google.com (mail-ot1-x336.google.com [IPv6:2607:f8b0:4864:20::336]) (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 ; Mon, 21 Oct 2019 15:23:54 -0700 (PDT) Received: by mail-ot1-x336.google.com with SMTP id g13so12438124otp.8 for ; Mon, 21 Oct 2019 15:23:54 -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=6sYjL86p7riDLGSsPOY/znpV47Gt4vhECBD2daiel2s=; b=kKLzkuR/l6UfDxe/U1CbjJVA2OkieqDT0+2koMjYKbV5S6BtdfeWOFVM+bqhjUvlMp bdTkVxidkL/Hdaqh9BF+f5V6Gz52kFK8+XTvfv68p+Ml1cSvix45j+le7oyeKj4G6sUX 2kDO6I7euUB/G6EJIO/a2KK0Nl1fPVFfvEm2918FzE8mkbDPEj9gT+33uuJz/3j5Uhwu iL6M2R1bxhIu6bmnVc6z60huUEZGkD3aSZGYm8orWPCEr6E3ibGLZWOgHpxqbvsaaASE BlWaR5EqBLcY7sn+BOSfWRHMFj38i4q9rTKCXwJAQ8CY7BXh8yqHcWANMP8eiPe9p9Wh CypA== 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=6sYjL86p7riDLGSsPOY/znpV47Gt4vhECBD2daiel2s=; b=hY7YI/sJXL2HlC19ow0KzZnU5rWMrBHVrza4HDPXVsx30JgrNF7RW+bSn1wloou1NO JsqbUP8uhYgd1wTNLhAsn2lFSxAGy85CH9HKjw6oRnAY2wqYz8DObYj38zgp+2Y3FVcs fFAaC3KgxEYQJi49samdtQ7d0vt9RiWHygBArRhThdCq7Ru/SFK6rB05nBIJmKmSHKnf G6XVoXd+N36ddAGYqaojasUcKd8d008FkS/+T1GoDFoOfvHVKXxzuoZ2/OxvPgE1p5Sp jcbd97MotBaTHRufs2g444gghkNwNPNhfna8QQUaaq0kdRzJpMjrxr7A7ZAeePw5z2Ei PCfQ== X-Gm-Message-State: APjAAAUaR2AZa+nYQy9FZSw6S5riCxndyNs6Nn++Ui1L4MdWVo5TyQGR vQjtsJQIVoIObALRSxq6gKsO2FzGvrP7Oi97Si1f2hQc X-Google-Smtp-Source: APXvYqxS1kkAmqeUr3VuDiMYBf5qaQzUWhY97mCjtf6jcj+YwKJuaagElRros2yPYF2frtLo1lJ11HdT7wxLtKT/zDE= X-Received: by 2002:a9d:422:: with SMTP id 31mr155413otc.107.1571696633564; Mon, 21 Oct 2019 15:23:53 -0700 (PDT) MIME-Version: 1.0 References: <3D85D31D-5DDD-42AA-B465-6ADBE72D952A@newclarity.net> <9A432898-EB7A-45C9-9C6F-AE6392B9B5C3@newclarity.net> In-Reply-To: Date: Tue, 22 Oct 2019 05:23:42 +0700 Message-ID: To: Mike Schinkel Cc: PHP internals Content-Type: multipart/alternative; boundary="00000000000089d269059573237d" X-Envelope-From: Subject: Re: [PHP-DEV] 'switch-expression' and the 'type guard' unary operator demo From: webdevxp.com@gmail.com (Kosit Supanyo) --00000000000089d269059573237d Content-Type: text/plain; charset="UTF-8" Hi Mike I think your hypothetical PHP syntax won't happen. Not because it's bad idea but because PHP just simply can't. I understand that you came up with that idea from Golang background but the reason Golang can do that because in Golang, assignments are statement not expression. Even `++` or `--` are statement in Golang. While assignments in PHP are expressions so they can appear in any expression contexts. And it will conflict with other places as Rowan said in previous reply. You could instead simply assume that case statements supports multiple > lines with the last providing the value, and thus not requiring the use of > an explicit `eval()`. > I'm not fond of implicit things. And I think my proposed solution is more useful because it can return value anywhere not just at the end. You might think it is complex or visually busy but others may feel it is more comfortable if they are able to write well structured and and cleaner codes by this way. Regards On Tue, Oct 22, 2019 at 3:42 AM Mike Schinkel wrote: > On Oct 20, 2019, at 11:11 PM, Kosit Supanyo > wrote: > > Ok, so let's look at a scenario. Will we be able to do this in the future, > if we decide to allow multiple expressions to result in a final value? > $y = switch ($x) { > case 1 => $arr = get_array(), array_pop($arr), > case -1 => $arr = get_array(), array_unshift($arr), > default => null, > }; > > As I told you in previous reply, I'm working on block-expressions as well. > So if PHP has block-expressions you can do the same this way: > > $y = switch ($x) { > case 1 => eval { > $arr = get_array(); > give array_pop($arr); > }, > case -1 => eval { > $arr = get_array(); > give array_shift($arr); > }, > default => null, > }; > > > I know you said you were working on block expressions, but I did not view > that as the best solution to the question I asked although I see that is > how you envision it. > > > > Which is obviously cleaner and more powerful. > > > That is arguable. I find the solution you proposed above that uses > `eval()` to be very "busy" visually, and needlessly complex/ You could > instead simply assume that case statements supports multiple lines with the > last providing the value, and thus not requiring the use of an explicit > `eval()`. But to do that would require semi-colon line terminators, I think. > > Note I also think `eval()` would also be a nice to have, but what would be > even nicer is if the inline switch did not require use of `eval()` to > support multiple lines per case. > > #fwiw > > -Mike > > > > > > > --00000000000089d269059573237d--