Glossary

Closure

A closure (anonymous function) is a nameless function that can be stored in a variable, passed as an argument, or returned from another function. Its key feature: it can "capture" variables from the enclosing scope.

Where it is used

Variable capture

$multiplier = 3;
$fn = fn($x) => $x * $multiplier; // captured automatically
$fn(5); // 15

In regular closures, capture is explicit via use ($var). To capture by reference — use (&$var).