> On Mar 25, 2021, at 12:50 PM, Rowan Tommins <rowan.coll...@gmail.com> 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 are 
saying:

    $x = 1;
    example(fn() {
       echo $x; // This would print "1"
       $x = 2;
       echo $x; // This would print "2"
    });
    echo $x;  // This would still print "1"

If that is what you are saying — which I did not get from your prior arguments 
— 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:  

    // 2nd set of parens acts as an implied "use":
    example( fn()(&$var) => $var = value() );

-Mike
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: https://www.php.net/unsub.php

Reply via email to