|
|
|
|
|
by cess11
315 days ago
|
|
You can do function ($parameter) use ($data) { ... }
to capture stuff from the local environment.Edit: And you can pass by reference: > $stuff = [1]
= [
1,
]
> $fn = function ($par) use (&$stuff) { $stuff[] = $par; }
= Closure($par) {#3980 …2}
> $fn(2)
= null
> $stuff
= [
1,
2,
]
Never done it in practice, though, not sure if there are any footguns besides the obvious hazards in remote mutation. |
|
My feeling is that this makes the code less legible. I'd rather write 5 lines of code that mutate an object or return a copy than do a pipe this way. I'm sort of not excited to start running into examples of this in the wild.