On 25/03/2021 16:24, Nuno Maduro wrote:
Concerning the comments about what's exactly "auto-captured" by the scope
of a multi-line short closure, we will be just reusing the "auto-capture"
feature that already exists in one-line short closures. Therefore, this RFC
doesn't have plans on changing the way "auto-capture" already works in PHP.


This may be technically true, but it's not particularly helpful. I'm not sure if the details are actually documented anywhere, and there's an awful lot of PHP code that either can't be used in a single-expression closure, or is extremely unlikely to be used.

For instance, which of the following will capture $a?

$assignedBeforeUse = fn() {
    $a = 42;
    echo $a;
}

$unreachableUse = fn() {
    if(false) { echo $a; }
    $a = 42;
}

$assignedBeforeUnreachableUse = fn() {
    $a = 42;
    if(false) { echo $a; }
}

$unsetRatherThanWritten = fn() {
    unset($a);
    echo $a;
}

$outerClosure = fn() {
    $nestedClosure = fn() {
        echo $a;
    }
}


Regards,

--
Rowan Tommins
[IMSoP]

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

Reply via email to