note 125709 deleted from functions.arrow by cmb
| From: | cmb@php.net | Date: | Fri, 22 Jan 2021 12:09:42 +0000 |
| Subject: | note 125709 deleted from functions.arrow by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-216216@lists.php.net to get a copy of this message | ||
Note Submitter: Hayley Watson
----
The variables in the enclosing scope captured by fn()'s body expression are ONLY the ones that
it explicitly mentions, not every variable in the enclosing scope.
<?php
$inner = 42;
$outer = 'inner';
$thunk_1 = fn($name) => $$name;
$thunk_2 = fn() => $$outer;
echo $thunk_1('inner');
echo $thunk_1($outer);
echo $thunk_2();
?>
All of those calls will fail because $inner is undefined.