Re: [RFC] Auto-capture multi-line closures and shortfunctions take 2
| From: | Peter Stalman | Date: | Thu, 25 Mar 2021 05:43:11 +0000 |
| Subject: | Re: [RFC] Auto-capture multi-line closures and shortfunctions take 2 | ||
| References: | 1 2 3 4 5 6 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-113757@lists.php.net to get a copy of this message | ||
On Wed, Mar 24, 2021 at 2:26 PM Mark Randall <marandall@php.net> wrote:
> To give my own example, earlier this week I wrote the following:
>
> $x = function () use ($to, $library, $thread, $author, $title,
> $library_name, $top_post) { ... }
>
> That was just to get those variables inside a callback that could be
> invoked inside a throw-aware buffering helper.
>
Hi Mark,
Have you considered using an array or DTO to pass the data?
You could also do this (although I'm not advocating it):
```
$vars = get_defined_vars();
$x = function() use ($vars) {
extract($vars);
/* ... */
};
```
Thanks,
Peter