Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:107601 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 50602 invoked from network); 21 Oct 2019 17:26:53 -0000 Received: from unknown (HELO php-smtp3.php.net) (208.43.231.12) by pb1.pair.com with SMTP; 21 Oct 2019 17:26:53 -0000 Received: from php-smtp3.php.net (localhost [127.0.0.1]) by php-smtp3.php.net (Postfix) with ESMTP id BB7252C04D4 for ; Mon, 21 Oct 2019 08:12:33 -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-il1-x130.google.com (mail-il1-x130.google.com [IPv6:2607:f8b0:4864:20::130]) (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 08:12:33 -0700 (PDT) Received: by mail-il1-x130.google.com with SMTP id t5so12316386ilh.10 for ; Mon, 21 Oct 2019 08:12:33 -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; bh=9okEz9dAd8t/w7zoCK6m0WYLYNAmdZiwGkoAQWiOfzs=; b=bvlE1qtKaBSIXBkhVZ9j+iEPzDb+XP4cZlHDzhbUiXSGUws/eowDKGLhkCBRrvoBb6 JDW8Au4FKjwnCakJB0+W9HmUmkL3ldzAhUPV+mdMADOVyGF6tOyuYNc1V1O0GDfPDIGO TEb+tzqxLWsX0+nEAbIWgLx2qZpqfrNPov3jxIacAae5uCTVLS+997qqkUzU5XsR8W7o ZMNjYk3pYuNkuXp86tH6kvddGotkr0hmUWXA/6QhkQRFO0WKyHlFQ2QuaSWheFzLzul2 41TISocELY+sVdzjqQys3FXHqi6/k/O/yBmDfBnbU1IJRj/iKUTlr4CtmmaT85q3SYGv YQqw== 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; bh=9okEz9dAd8t/w7zoCK6m0WYLYNAmdZiwGkoAQWiOfzs=; b=GTm7W7uQ5r9QUh8oTu3MVQGRiEOjXoZABLTfdAlaloVbY5p9Dz2Bpv9+vx4gdmmnQw YsTNdKbtG6okcv7uBm7vcwlZrxAUzJmfVkpy9o7y0JVQK2MLDc5oYLvxG4dJj5kvtSKQ UF5C/7D08/Sg2+U/YqzAoBe4kJtOiZRqSfqxOeqoHyzn30xHmBpri7otcFm3vJe0lSYP KsbKPHNbUcV6pndSQrzKQSZWtEK1EvWBCMxgKfiK+4hTralhGhFlw69kTMkkSj5n+RzN p7+c21S1AGnIc/obt8bM1y6x5dsXsRCPjwKJiU10ZFNMaPlKdb7DgwxhviQhSMFUQSqm 25fA== X-Gm-Message-State: APjAAAXEl/QRHvn0dgbXOH6w5EoiE4ja7D9DETYzoekAK+EFo4ZGmo0l HvP0DnJoQzeTLGYY1vR+BMtZHDp6YbfzqtVDElQ0fg== X-Google-Smtp-Source: APXvYqzo2u4n1ZturVkpzOMMPVKnnqUDBfM+XDIuZr5uekp7Kf4zlnNPu+1bw2e7+S3Q/uufbOwU8vjnxyW7PvZemtU= X-Received: by 2002:a92:4144:: with SMTP id o65mr27283031ila.206.1571670752336; Mon, 21 Oct 2019 08:12:32 -0700 (PDT) MIME-Version: 1.0 References: <3D85D31D-5DDD-42AA-B465-6ADBE72D952A@newclarity.net> <9A432898-EB7A-45C9-9C6F-AE6392B9B5C3@newclarity.net> In-Reply-To: <9A432898-EB7A-45C9-9C6F-AE6392B9B5C3@newclarity.net> Date: Mon, 21 Oct 2019 16:12:21 +0100 Message-ID: To: PHP internals Content-Type: multipart/alternative; boundary="000000000000e5a63b05956d1cf2" X-Envelope-From: Subject: Re: [PHP-DEV] 'switch-expression' and the 'type guard' unary operator demo From: rowan.collins@gmail.com (Rowan Tommins) --000000000000e5a63b05956d1cf2 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Mon, 21 Oct 2019 at 15:13, Mike Schinkel 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, > }; > Unlike some languages, not every statement in PHP is a valid expression (e.g. you cannot write "$foo =3D echo $bar"), so regardless of whether we u= se commas or semi-colons, the right-hand-side in those examples would have to be some new construct, so we could choose whatever syntax we wanted for it. We'd probably want something other than bare commas anyway, to make it more widely usable, e.g. in array declarations. If what you want is a full *statement* block on the right hand side, then you'll need to use the current switch statement anyway. > What if in the future PHP implements variadic syntax for assigning to > arrays, e.g. $var =3D 1,2,3 where $var could satisfy a $variadic paramete= r > set of parameters w/o requiring `...`? If PHP embraces that =E2=80=94 n= ote GoLang > has something similar =E2=80=94 then will comma syntax allow for it with = hacky use > of parentheses? > $y =3D switch ($x) { > case 1 =3D> $var =3D 1,2,3, $var[1], > case -1 =3D> $var =3D 9,8,7, $var[1], > default =3D> null, > }; I'm not really clear what feature you're suggesting here, but I'm pretty sure it conflicts with existing uses of commas, so shouldn't constrain us from using them elsewhere. foo(1,2,3); foo($var =3D 1,2,3); $a =3D [0, $var =3D 1,2,3]; // etc Regards, --=20 Rowan Tommins [IMSoP] --000000000000e5a63b05956d1cf2--