Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:113791 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 54414 invoked from network); 25 Mar 2021 17:23:57 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 25 Mar 2021 17:23:57 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id B16F31805A7 for ; Thu, 25 Mar 2021 10:20:00 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,HTML_MESSAGE, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail-vs1-f42.google.com (mail-vs1-f42.google.com [209.85.217.42]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Thu, 25 Mar 2021 10:20:00 -0700 (PDT) Received: by mail-vs1-f42.google.com with SMTP id h25so1302982vso.2 for ; Thu, 25 Mar 2021 10:20:00 -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=rmpCNnN1LlOahrFKcZP43gUcghYuoPtYEXxQ4CxWDFc=; b=NAbHMYN1LJgGXqubhkNE3EDHELO1Puvul3GGNKy7NeZ8u33WL9jjWTTHDzBEroustz 6GOxKFuywe9H1J3sGqbINPMZMl33uTfGck3NIH/lw97oRA6NtVyI7HqsZZXOP+WsrioU VvZKbPs5LMKWPZConaYsu4bF/u3ZYYX9AQ+AhoIWRL99l3XwBUrK+lprGuv891zBjGzy U4gTlfxo+swd9JbgJpU5DGYtOTj09GWDSfgL9i1RxyDqkTi0mANo4HNL0S5n+rQEN0Ba kLCI8m/C0peW3VC8JW82sSB+JvnA0mT4I1pPGAwrT/nhieVGkrY/0xzAGwTaEQe6oV/u 1qBA== 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=rmpCNnN1LlOahrFKcZP43gUcghYuoPtYEXxQ4CxWDFc=; b=br+juyDQpk1BVlVnOl+giKsYIx8UTr3xhGL/sYzzBsrJrvS7VYPgdv4zebUy605bHv BJj2DNAO0qzifKDYa0cmgyPWK3J6j4AszhLLpxDGI/L6poaTE10YbKSzLYVZ7kLkpge2 OkQzxOuXmbL19DUwi+kSVSO/9pzgHfnN5IamtQHe+bpC5P8BOnJnQSXXheM1O3i0IRhk gHSc1Z6wA2vMJa7pJKJ90yKNp1XQkWkmOl0hzCPnL1PnzG4FpLSjEoc1xRZJayzG9vdb bFEiUMUH/1couJq9xgTHXu7GJKMzeknkyc5BPqd4Gi6G3JtCizoFw0VEA1UGUT+xAclx y0DA== X-Gm-Message-State: AOAM532OBcJBp53kYHMcZPcCA33x5xRil9vl2y/qzOn9hn9TSpcedoyt GJlueG368hpktz3lQFAAeMqAowXfIM330pmCgt4Y96g2+lE= X-Google-Smtp-Source: ABdhPJxA85z41O/Re9ddT4E1u2gpg1X0by/jUgH0utdx5ZpQngTwqFY9fo77OjCzyt4WxMet2E2Yr7syrQ+3i6eFgWk= X-Received: by 2002:a05:6102:22c8:: with SMTP id a8mr6221901vsh.13.1616692799254; Thu, 25 Mar 2021 10:19:59 -0700 (PDT) MIME-Version: 1.0 References: <88c9eb5f-f80c-4869-b7f8-1b58b9e2eaa3@www.fastmail.com> <4DC3B66E-A91A-4AA9-8872-8EE9DE92C2D4@cschneid.com> <8c72c162-83c0-7c7f-2fa7-4fbe3fb30a4a@gmail.com> <605bae82.1c69fb81.f49f7.d11eSMTPIN_ADDED_MISSING@mx.google.com> <919e30e7-3e5e-d955-7bb4-1e1b5825cdd1@gmail.com> <635DD146-FC6F-4991-8D2C-5A6B492722D5@newclarity.net> <734f12de-da98-6b76-c2fe-8682f4d177aa@gmail.com> <36E45DD6-E2BD-4801-BAAE-4355C83D1AC3@newclarity.net> <538F5888-4B42-42AA-8312-872A836B0FB9@newclarity.net> In-Reply-To: <538F5888-4B42-42AA-8312-872A836B0FB9@newclarity.net> Date: Thu, 25 Mar 2021 13:19:47 -0400 Message-ID: To: Mike Schinkel Cc: Rowan Tommins , PHP internals Content-Type: multipart/alternative; boundary="00000000000002bc6405be5fa077" Subject: Re: [PHP-DEV] [RFC] Auto-capture multi-line closures and shortfunctions take 2 From: chasepeeler@gmail.com (Chase Peeler) --00000000000002bc6405be5fa077 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Thu, Mar 25, 2021 at 1:14 PM Mike Schinkel wrote: > > On Mar 25, 2021, at 12:50 PM, Rowan Tommins > wrote: > > > > On 25/03/2021 15:02, Mike Schinkel wrote: > >> Can you please clarify why "function(...) use(...) {...}" can't be > their solution when someone needs by-reference capture? > > > > > > For the same reason - or lack of reason - why it can't be the solution > when they need by-value capture. In other words, whatever reason people > have for wanting this RFC. > > Are you proposing auto-capture but one that is note able to change the > variable's value in the outer scope? > > Since code is worth 1000 words, here is an example of what I think you ar= e > saying: > > $x =3D 1; > example(fn() { > echo $x; // This would print "1" > $x =3D 2; > echo $x; // This would print "2" > }); > echo $x; // This would still print "1" > > If that is what you are saying =E2=80=94 which I did not get from your pr= ior > arguments =E2=80=94 then I myself would be fine with "by-value" capture. > > What I like about the RFC is being able to omit the use(...) when > referencing (reading) a variable inside the closure that come from the > outer scope. But almost all of my use-cases would work fine with by-valu= e > semantics, and for the rest I could use "function(...)use(...){...}." > > That said, I again suggest this we could omit the "use" keyword for short > functions: > > // 2nd set of parens acts as an implied "use": > example( fn()(&$var) =3D> $var =3D value() ); > > That wouldn't work though if example expects a callback with a defined signature. "Use function() use()" in that case might be a valid solution, but just wanted to throw it out there. Silly example: $counter =3D 0; array_map(fn($a) =3D> {$counter++; return $a+1},$array); If you tried to pass in $counter as a parameter, it would fail. > -Mike > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: https://www.php.net/unsub.php > > --=20 Chase Peeler chasepeeler@gmail.com --00000000000002bc6405be5fa077--