Newsgroups: php.internals
Path: news.php.net
Xref: news.php.net php.internals:112147
Return-Path: <php@golemon.com>
Delivered-To: mailing list internals@lists.php.net
Received: (qmail 82554 invoked from network); 30 Oct 2020 03:31:47 -0000
Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5)
  by pb1.pair.com with SMTP; 30 Oct 2020 03:31:47 -0000
Received: from php-smtp4.php.net (localhost [127.0.0.1])
	by php-smtp4.php.net (Postfix) with ESMTP id 982AA1804CC
	for <internals@lists.php.net>; Thu, 29 Oct 2020 19:51:05 -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.4 required=5.0 tests=BAYES_00,
	HEADER_FROM_DIFFERENT_DOMAINS,HTML_MESSAGE,RCVD_IN_DNSWL_NONE,
	RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_SOFTFAIL autolearn=no
	autolearn_force=no version=3.4.2
X-Spam-Virus: No
X-Envelope-From: <php@golemon.com>
Received: from mail-lf1-f41.google.com (mail-lf1-f41.google.com [209.85.167.41])
	(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 <internals@lists.php.net>; Thu, 29 Oct 2020 19:51:04 -0700 (PDT)
Received: by mail-lf1-f41.google.com with SMTP id y184so4017265lfa.12
        for <internals@lists.php.net>; Thu, 29 Oct 2020 19:51:04 -0700 (PDT)
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=nVHDOnwh0Tzlz/1tQl9Ky7H4S3TkK4NQcyfiYTsDhLQ=;
        b=RnOU2BSmx86RjldMlv31831G8hupnvpTKO/hel3KrkPvuCTt9ovKj4TtwDNinv28K2
         CMwTm1QEUw9uz16wPdDP5tWrl3M3JEpzbxWRdEqZAkrNM9MYag1fc8Ee7X5iYQjbc6zI
         XEWueiAea3K7GhFjR7/BHrUw6IKhK7SOPRhobXOSiItqYD72OrPydab0YV/cclj9FwMD
         JZFHcItX9rN1FNvcF2Fj+8JBWfBlEzO/2ccYBzeHk96SECupK3Y6frnCtedxnpHuTED1
         94htLywi+KX4BQTTetQlAezD5LFI6XnTMUB83nUFCESobbnVYB+f0WIwA5g61z15E+g1
         vBHw==
X-Gm-Message-State: AOAM5323LwHY74hpHZ/Akkvd9EWPnSBD72A45VEpuX6c4/agJ9gyJ92O
	z9LFr1SQMRmx0p6FpFPt14hND2FIrG6xlHd2yTX8rg==
X-Google-Smtp-Source: ABdhPJwqSYl62Tz1kruqmQibgtdnA8ps3ggdxyAnwAKMTZ2wIiZlVrFMwt7y54mPhPwAfyITTxaVdiMSyiogBRy3Ezg=
X-Received: by 2002:ac2:57cf:: with SMTP id k15mr13777lfo.501.1604026261538;
 Thu, 29 Oct 2020 19:51:01 -0700 (PDT)
MIME-Version: 1.0
References: <CALZWoqU_qQQiQ5O6Pa8Upxo2FYZ2hpMA0dy9=CZndeEFsijgxA@mail.gmail.com>
 <446c9894-191f-e53b-4534-31c4e7b91d7b@gmail.com> <881e2335-5f81-0d79-6a17-06bc20f14223@gmx.net>
 <7e50dba8b8749b9e32c803d7ded20fab84e21dc74ec9a55d8127e961bb036cd8@mahalux.com>
 <CANS-=pf0J3kmybt69a6uhPO8QmCJtBGoHat+x4ngp0AqJpX9+w@mail.gmail.com>
In-Reply-To: <CANS-=pf0J3kmybt69a6uhPO8QmCJtBGoHat+x4ngp0AqJpX9+w@mail.gmail.com>
Date: Thu, 29 Oct 2020 21:50:50 -0500
Message-ID: <CAESVnVoxWWmru-5JrO06d3jDHtO6oCm3PpUQS1L8zm9+v0bMxg@mail.gmail.com>
To: Lynn <kjarli@gmail.com>
Cc: =?UTF-8?B?TWljaGFlbCBWb8WZw63FoWVrIC0gxIxWVVQgRkVM?= <vorismi3@fel.cvut.cz>, 
	Andreas Leathley <a.leathley@gmx.net>, PHP internals <internals@lists.php.net>
Content-Type: multipart/alternative; boundary="000000000000879e3205b2da77cd"
Subject: Re: [PHP-DEV] RFC: Support for multi-line arrow functions
From: pollita@php.net (Sara Golemon)

--000000000000879e3205b2da77cd
Content-Type: text/plain; charset="UTF-8"

On Mon, Oct 5, 2020 at 5:09 AM Lynn <kjarli@gmail.com> wrote:
> How should php deal with the scenario where you want to `use` everything
> and have one variable by reference?
>
> ```
> function () use (*, &$butNotThisOne) {};
> ```

I would take a page out of C++'s book here.  In C++ a closure is (some of
these bits can be omitted for brevity, but I'm not going to describe those
here as it's orthogonal to the topic):

[capture, vars](type argName) -> returnType {
  statements;
  return retVal;
}

Looking specifically at the capture vars section (in the example we are
capturing two variables, one named 'capture', one named 'vars'), there are
wildcards available as well:

[=](bool bval) -> void {}

The equal sign (as above) captures all variables used in the closure by
value.
Similarly, the ampersand `[&](int ival) -> void {}` captures all variables
used by reference.

Exceptions can be added to that list just as you suggested, so:

[=,&foo](double dval) -> double { return foo + dval; }

Or

[&,foo]() -> void { doSomething(foo); }

I think we could apply the same in PHP terms:

function(float $dval) use ($, &$foo) { return $foo + $dval; };
function() use (&$, $foo) { doSomething($foo); };

Plus or minor for parser convenience.

-Sara

--000000000000879e3205b2da77cd--