Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:113789 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 51568 invoked from network); 25 Mar 2021 17:18:08 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 25 Mar 2021 17:18:08 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id DF96F180549 for ; Thu, 25 Mar 2021 10:14:11 -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,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 10:14:11 -0700 (PDT) Received: by mail-qt1-f176.google.com with SMTP id x9so2191241qto.8 for ; Thu, 25 Mar 2021 10:14:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=newclarity-net.20150623.gappssmtp.com; s=20150623; h=mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=esYmpLaQh4Dfk14ipJQrvS5JvIFgXLP5k230wEzus4o=; b=AJBWPX3kKSkjy6tLKsPMLSP89sshu62TfAWKfByOAFnk4YJwsELXwvc1nsRpXOoAZf ycS8Ru8N+CHoL5CVZbFwAfZWw8YnvVAHnjyBAOEwc5DUMJ4mrIch+YJLccmlUjLOW/Uw 39ml1b2A1Y+ACOv32r5ASgVQeGSIieEnYqzX+6qoOfT9VKrhAuSz3vwP5qRk0AFUCYlh hPZEuLDAjctckpZL7jPbON5BcSpt7/aqSprY9pmm2/ujzone1J1pdw4/u8osiHLGmiVM Vz7lEII1prlE70rqdyrgL3yEjBr+gg0UWjYkaZf9kOSaj1Fs7qa7QkM7W1aB5+Ae7JO4 N/gg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=esYmpLaQh4Dfk14ipJQrvS5JvIFgXLP5k230wEzus4o=; b=V4suXAHtQIPIk5EZpdpIbLMcsm7Y9YXSaxyJfa1xvry5kjsVDplJI6BkflfLzhiTWF Bln/4jCMl0zE4WaG/M+fVfiyMGI6EnvORbDTII86EXLKHYWZQAJ2/LbLU3VGaMk1lTzA UWJGnrWJFqIuoii0MW6haZ0/tfihOJOZ5TX/+IYssULdUnrMG9tkL9e5xgIVE5RFyT5C hCO5J5n7DKUrXwU/aUYfQ+7Vu8ImXoCGhDMZysfmf+EUc9C7xi6PQJ7do8XsAIbTyWO7 CIuNuBpLZ6QS2j8s2eDjDq9gyE8uoqranxiiNN37PLAbct+bzR1yM+UywcbDKK+4rhpj gxNA== X-Gm-Message-State: AOAM532uCwPXa5pyfee5Sy0jZoB9YXfHGWTaUfaoizSCPrhtb7qOnK8D dLg2L6s65ShZG4+Dx2TdVbRlhg== X-Google-Smtp-Source: ABdhPJzN+g1WzuPXoPFaJaSwvmvpjBM/5Zu0wy7weFPTJCj1lgUj4uCRF+tK8UICUQTBPOj0LDSFxg== X-Received: by 2002:ac8:6c5d:: with SMTP id z29mr8781017qtu.99.1616692450027; Thu, 25 Mar 2021 10:14:10 -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 v6sm4363927qkf.132.2021.03.25.10.14.09 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 25 Mar 2021 10:14:09 -0700 (PDT) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 13.4 \(3608.120.23.2.4\)) In-Reply-To: Date: Thu, 25 Mar 2021 13:14:09 -0400 Cc: internals@lists.php.net Content-Transfer-Encoding: quoted-printable Message-ID: <538F5888-4B42-42AA-8312-872A836B0FB9@newclarity.net> 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> To: Rowan Tommins 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) > 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. Are you proposing auto-capture but one that is note able to change the = variable's value in the outer scope? =20 Since code is worth 1000 words, here is an example of what I think you = are 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 = prior 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-value 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: =20 // 2nd set of parens acts as an implied "use": example( fn()(&$var) =3D> $var =3D value() ); -Mike=