Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:107617 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 42806 invoked from network); 21 Oct 2019 22:56:43 -0000 Received: from unknown (HELO php-smtp3.php.net) (208.43.231.12) by pb1.pair.com with SMTP; 21 Oct 2019 22:56:43 -0000 Received: from php-smtp3.php.net (localhost [127.0.0.1]) by php-smtp3.php.net (Postfix) with ESMTP id A4BB32D2019 for ; Mon, 21 Oct 2019 13:42: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=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,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-yw1-xc35.google.com (mail-yw1-xc35.google.com [IPv6:2607:f8b0:4864:20::c35]) (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 13:42:27 -0700 (PDT) Received: by mail-yw1-xc35.google.com with SMTP id m7so5414584ywe.4 for ; Mon, 21 Oct 2019 13:42:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=newclarity-net.20150623.gappssmtp.com; s=20150623; h=from:message-id:mime-version:subject:date:in-reply-to:cc:to :references; bh=5mltMZhcXEnnS/skTY3emV20bBTffa71iYga26dMZzA=; b=cBPpjGcsJ9OTbATlLYkJolwdPY5XU6Qt6Hu1OpQix+RtJTtkqu3Fc4ffMJbxWMIjOd 8OZRo5BsYZ114/ZQl0+ruYCU4g5d1ZrQzZdx2cSIxR+Xh5oZZEUIiBqs1MrRGPU1Xpnm TjpQzCpQPREAnS8ZO+ZdkQEq5Y3y3l5RWoS3N+ENcEIwCVajhhepZiABVOcQd2F6Q/AZ IJ7TJIu3WLEz4uHgMxN5ypwxhLq4WJKVNmxA15PNcDG9z+UDqlOHIvxxO8Ubv/fY3t66 DQI4lnTQMKYePJeqLGWwkuFYvVP4u32fGogvUPukMCb6xTU6VxcSm26G6uqa1Xm9eor+ CmYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:message-id:mime-version:subject:date :in-reply-to:cc:to:references; bh=5mltMZhcXEnnS/skTY3emV20bBTffa71iYga26dMZzA=; b=mmHHovZQIv3kK5R44d6bog+FTXwBOD3TwL4GMyhiXU0FOlKUdPGcvMtXk4pkRJzrEC acPcYlnWrTVc2FfJXs0YJoxbDTqv9iYQmOSsgaA6aup7ZQum1Dju/KtglTlkyfysUoxP l1xDLHKRSI1TK9Y8Flx2iZb/IUQb2xK596kBjp/pmhC1liD7sb7iqJ4eAJLLI2e3zCgY 2aeDbkzKyG50AgLM88iTuTDeBLYacwRGCIJgjvIZWOpbNgQ9G3vxNRtChgM0Q+gBPJTg SaiSx0F/blmjgRRuSvF52BVJ5fnwoJFsnEHKWx6RIwxy5UhWIQoaujHYGCHQv2vvrvqy clqA== X-Gm-Message-State: APjAAAUT/cnF4N5uC5dvPX4d1A+B83ctAn6GJSWyVnFx2APb2S8A1t2D O9LCFV51vGRCKP37mEK03+TA9w== X-Google-Smtp-Source: APXvYqwLlqzpp3Y0uwNSQ9ZiAAERvvgM9zoDO7HHSnp/s62ML1RoPQGmcJuzI2bEqw6IEB68fc2xTA== X-Received: by 2002:a81:a042:: with SMTP id x63mr581632ywg.301.1571690547218; Mon, 21 Oct 2019 13:42:27 -0700 (PDT) Received: from ?IPv6:2601:c0:c67f:e34e:90d7:91e4:da1d:b8e6? ([2601:c0:c67f:e34e:90d7:91e4:da1d:b8e6]) by smtp.gmail.com with ESMTPSA id n11sm3930080ywh.82.2019.10.21.13.42.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 21 Oct 2019 13:42:26 -0700 (PDT) Message-ID: Content-Type: multipart/alternative; boundary="Apple-Mail=_2EB5D28D-9F9F-4016-89B8-1DB9134BE579" Mime-Version: 1.0 (Mac OS X Mail 12.4 \(3445.104.11\)) Date: Mon, 21 Oct 2019 16:42:25 -0400 In-Reply-To: Cc: PHP internals To: Kosit Supanyo References: <3D85D31D-5DDD-42AA-B465-6ADBE72D952A@newclarity.net> <9A432898-EB7A-45C9-9C6F-AE6392B9B5C3@newclarity.net> X-Mailer: Apple Mail (2.3445.104.11) X-Envelope-From: Subject: Re: [PHP-DEV] 'switch-expression' and the 'type guard' unary operator demo From: mike@newclarity.net (Mike Schinkel) --Apple-Mail=_2EB5D28D-9F9F-4016-89B8-1DB9134BE579 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii > 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 =3D switch ($x) { > case 1 =3D> $arr =3D get_array(), array_pop($arr), > case -1 =3D> $arr =3D get_array(), array_unshift($arr), > default =3D> null, > }; >=20 > 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: >=20 > $y =3D switch ($x) { > case 1 =3D> eval { > $arr =3D get_array(); > give array_pop($arr); > }, > case -1 =3D> eval { > $arr =3D get_array(); > give array_shift($arr); > }, > default =3D> 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 --Apple-Mail=_2EB5D28D-9F9F-4016-89B8-1DB9134BE579--