Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:113795 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 64134 invoked from network); 25 Mar 2021 18:32:56 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 25 Mar 2021 18:32:56 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 33AFD1805A7 for ; Thu, 25 Mar 2021 11:28:58 -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=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HTML_MESSAGE,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2, SPF_HELO_NONE,SPF_NONE autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail-qt1-f176.google.com (mail-qt1-f176.google.com [209.85.160.176]) (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 11:28:57 -0700 (PDT) Received: by mail-qt1-f176.google.com with SMTP id y2so2362758qtw.13 for ; Thu, 25 Mar 2021 11:28:57 -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=Tr2gJv1uJPBkYndHDmi85009dg8Gzkf0nquQIOxLWm8=; b=1LpW95zj7Rj58Z3uCdVhy+d4rYLHDIhrdHoarj1XluGkXF3RzqVXJoHow7EIPS/LI6 MirHJunFmxS+wEtRfLnxLdC9pwy47RN/pFF1VRSN3xx/lerdkxAPVoO269nQzRmVa1UF O66KodfMODdc/VH6Le9gWVJC5PNoudBhrfqnM302yNWY5zv9frsJzExRewTSXDSAv2Ao 1mXHKqJCJVvABRfAF6OPoU+CSJsYnY0ZVHGPj0cdB/arME/79eG1/02DsVsFoGpiBBQV mIy6Ws0/fOtW8HkXTZ2AXE7xttaguyTdBvsmm+ioOMZahY1clfwNL7E0WoOrU7IgAqEs EQLA== 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=Tr2gJv1uJPBkYndHDmi85009dg8Gzkf0nquQIOxLWm8=; b=bwQ85x1zFVKOdqwmIAljfFx/esxx5ssBx4RXLs5s1XdDY8t2U7ZyXL3vLZ6NpqfLre PJ9HZtaBHUMZPexK1CFhsBD/PbCDJPEq1fpVFogew77AmsStyoaTqsuKH51l/8/y+KZ9 eto8zo06RRLpnTVbkqTTU5xqXA7b3fk5c/TrBpCcXCX7Ao4D+3zCwaf/QipJAOgNcD4B bEJUKTjuNROlyZTGnSuBtxegiA8WF6ARXlzRr/s4uaPu/N2d+BErqUHZcv7rCPWwzJCm fwGLjBZWY3VBG/v3i/sJ4z/OI312/LRHPAaLstJV7y4AXSm4h+7epQjN7urvxxnOPKkN 4V+A== X-Gm-Message-State: AOAM532IG8vVt30iNJpzC5+vahIc/tSUuGLDnVABQNHpmM9ancH+/I5y RagXCqx58jsX3IDMqCOFCtzZK885YWbKtPrN X-Google-Smtp-Source: ABdhPJw+mnDSynbbUNw/bbLg0ZETpq4uf+sXknZyMKofZNb7NHL83oV/ts4sqHnYw9wrQ2GlpNMP8Q== X-Received: by 2002:aed:29e5:: with SMTP id o92mr8749339qtd.29.1616696936762; Thu, 25 Mar 2021 11:28:56 -0700 (PDT) Received: from [192.168.1.239] (c-24-98-254-8.hsd1.ga.comcast.net. [24.98.254.8]) by smtp.gmail.com with ESMTPSA id 73sm4739047qkk.131.2021.03.25.11.28.55 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 25 Mar 2021 11:28:56 -0700 (PDT) Message-ID: Content-Type: multipart/alternative; boundary="Apple-Mail=_A589D705-BED4-4AB8-9BE7-ED01172B4A03" Mime-Version: 1.0 (Mac OS X Mail 13.4 \(3608.120.23.2.4\)) Date: Thu, 25 Mar 2021 14:28:55 -0400 In-Reply-To: Cc: PHP internals To: Chase Peeler 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> X-Mailer: Apple Mail (2.3608.120.23.2.4) Subject: Re: [PHP-DEV] [RFC] Auto-capture multi-line closures and shortfunctions take 2 From: mike@newclarity.net (Mike Schinkel) --Apple-Mail=_A589D705-BED4-4AB8-9BE7-ED01172B4A03 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 > On Mar 25, 2021, at 1:19 PM, Chase Peeler = wrote: >=20 > On Thu, Mar 25, 2021 at 1:14 PM Mike Schinkel > wrote: > > On Mar 25, 2021, at 12:50 PM, Rowan Tommins > wrote: > >=20 > > 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? > >=20 > >=20 > > 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. >=20 > Are you proposing auto-capture but one that is note able to change the = variable's value in the outer scope? =20 >=20 > Since code is worth 1000 words, here is an example of what I think you = are saying: >=20 > $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" >=20 > If that is what you are saying =E2=80=94 which I did not get from your = prior arguments =E2=80=94 then I myself would be fine with "by-value" = capture. >=20 > 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-value semantics, and for the rest I could use = "function(...)use(...){...}." >=20 > That said, I again suggest this we could omit the "use" keyword for = short functions: =20 >=20 > // 2nd set of parens acts as an implied "use": > example( fn()(&$var) =3D> $var =3D value() ); >=20 >=20 > 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. True. But is that really any different than this failing: example(1); When the signature is this? example(string $x) {...} -Mike --Apple-Mail=_A589D705-BED4-4AB8-9BE7-ED01172B4A03--