Closure

Closures are anonymous functions: functions without a name. They are also supported by the eponymous Closure class in PHP.

They are close to the arrow-functions. They are also created with the ... operator, also known as the first class callable.

<?php

    $closure = function ($a) use ($b) {
        return $a + $b + 1;
    };
    print get_class($closure); // Closure

    $closure2 = strtolower(...);
    print get_class($closure2); // Closure

    $closure3 = fn($a, $b) => $a + $b;
    print get_class($closure3); // Closure

?>

Documentation

See also Closure Optimisation (8.6).

Related : static, Arrow Functions, Anonymous Function, First Class Callable, Callables, Callbacks, Anonymous Class, Closure Binding, Functions, Return, Sort, Use, Callable Arrays, Array Callback, Bind, Inherited Variable, Closure Class, Custom Function, Lexical Variable