What are Anonymous Functions (Closures) and how do they use the use keyword?
Last updated
A closure is an unnamed function (an instance of
Closure) assignable to variables or passed as a callback, e.g. toarray_maporusort.Closures don't see outer variables automatically:
useimports them by value (snapshot at definition), or by reference with&so changes propagate.Arrow functions (
fn() =>, PHP 7.4) capture outer variables by value automatically, so they need nouse.