Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:107614 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 32076 invoked from network); 21 Oct 2019 22:32:50 -0000 Received: from unknown (HELO php-smtp3.php.net) (208.43.231.12) by pb1.pair.com with SMTP; 21 Oct 2019 22:32:50 -0000 Received: from php-smtp3.php.net (localhost [127.0.0.1]) by php-smtp3.php.net (Postfix) with ESMTP id 83D6E2D19C3 for ; Mon, 21 Oct 2019 13:18: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=-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-xc34.google.com (mail-yw1-xc34.google.com [IPv6:2607:f8b0:4864:20::c34]) (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:18:32 -0700 (PDT) Received: by mail-yw1-xc34.google.com with SMTP id g77so1339462ywb.10 for ; Mon, 21 Oct 2019 13:18:32 -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=48khadCjjSZ5EJTlxP6qkXQ3DtpMxPObutI9U2LOUXE=; b=x00UbcHKfeE9BCsABLiLA2GjemaeFoTL4BljkrVP+XwpXipuIhDH9CB6MrK4qbI39+ ghQ/O8xqNsYYf9C0CgJU35ZJxSAwR5pTFbVguyFQNt+PsyhGWjDpdEaqY3mPGlp7pfgF zpX7fAKrpEp5w7pTSRcCkugYGp2FNylpL5cs1X12KoOuslJOInKqd4gsM9uav66rIu2g GeUSUQ4vHZz21o1y1rX+YR+vEm4c2dr/GbQlrrHxZZdu9Oyj9U1sPtsXdVC33xPBXP+5 sRcttZrOKJnIWIgpD1BkrZCJDEEnFgkn4wLsHJhd0jKM8jnefm7OdL+Ci8JYflxCkCzK xT0A== 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=48khadCjjSZ5EJTlxP6qkXQ3DtpMxPObutI9U2LOUXE=; b=Ndf5MoM41hO/aX/RQ/RdeEepoemOBw8WaO4EpDUVImSqmjG2CbCI98NTPb38AyxARw QXw0NB5uZWNbwNgfQnkLB3vPzqf1N7zoxivbZflbvClbXQT3JL8sT9j1CBNrFkCJPmDz H+jTMSEerssOjgvdBmeaZVvKT4QSMkap2cE6I4DdAovspVK5CfP8JSh/CF1ZgV0AO8lM BXhsgrKKkrxyZhfgcaubEin+Hgc2YoErt7dgOet3NLh0W7gyThaQFKL3xg80aNG9Dun9 3eD8fu0FpLewQKzmqFpeYCRF/QRlUPxKVJE4zZu3v/m+S7HL0nSQ/5HEZATva+aioNEg GOwA== X-Gm-Message-State: APjAAAXwzu6bMd4pxbhR9c52JbTE29J4hi4z2sTeNl3yi5W6bXuGDnXo jm1osMoWfb/kpEeRXOnQCeBWSQ== X-Google-Smtp-Source: APXvYqwnA9t3/LObQy1yFNcpmSHHF2hS+Gh2av3EK03tNP+DQT0PKQ24uy0IbrF/vmMTJgKLZLxE1A== X-Received: by 2002:a81:9486:: with SMTP id l128mr575863ywg.334.1571689112225; Mon, 21 Oct 2019 13:18:32 -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 l21sm3405128ywl.0.2019.10.21.13.18.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 21 Oct 2019 13:18:30 -0700 (PDT) Message-ID: <10B38D5F-C2BF-4657-BC58-B302C096A18F@newclarity.net> Content-Type: multipart/alternative; boundary="Apple-Mail=_968F5891-E3FA-4E4C-8BBC-AF83A7B45FD5" Mime-Version: 1.0 (Mac OS X Mail 12.4 \(3445.104.11\)) Date: Mon, 21 Oct 2019 16:18:29 -0400 In-Reply-To: Cc: PHP internals To: Rowan Tommins 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=_968F5891-E3FA-4E4C-8BBC-AF83A7B45FD5 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 > On Oct 21, 2019, at 11:12 AM, Rowan Tommins = wrote: >> 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 = parameter >> set of parameters w/o requiring `...`? If PHP embraces that =E2=80=94= note 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, >> }; >=20 > 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. >=20 > foo(1,2,3); > foo($var =3D 1,2,3); > $a =3D [0, $var =3D 1,2,3]; > // etc You may well be right.=20 But to follow up to clarify what I was thinking consider the following = (hypothetical) PHP syntax. Note that the return value has two comma = separated values, and the assignment can accept those multiple values = into two comma separated variables in the assignment: function read_file(string $filepath):string,PHP\Error { $content =3D file_get_contents( $filepath ); $error =3D false =3D=3D=3D $content ? new PHP\Error( "failed to open '%s'", $filepath ) : null; return $content, $error; } $content, $err =3D read_file( __DIR__ . '/myfile.txt' ); if (!is_null( $err ) ) { error_log($err->message); } Now yes I know we can do this with arrays and list(), but I have never = seen anyone do this in the wild and hence I think it is not idiomatic = PHP. And I hypothesize they do not do this because it is ugly to read = and write and because PHP will throw a runtime error (vs. load-time = error) if you have fewer values returned than you assign: function read_file( string $filepath ): array { $content =3D file_get_contents( $filepath ); $error =3D false =3D=3D=3D $content ? new My\Error( "failed to open '%s'", $filepath ) : null; return array( $content, $error ); } list( $content, $err ) =3D read_file( __DIR__ . '/myfile.txt' ); if ( ! is_null( $err ) ) { error_log( $err->message ); } With the first example PHP could type check at load time vs. having to = wait for coverage of this code at runtime, and `:array` type hint in the = latter is not as good as the `:string, PHP\Error` type hint of the = former. I am probably having unreasonable expectations to believe we will ever = see this type of thing in PHP. Still I hold out hold and want to = register an objection if I see new syntax that would make this syntax = impossible in the future. #fwiw -Mike --Apple-Mail=_968F5891-E3FA-4E4C-8BBC-AF83A7B45FD5--