Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Closure

Closures, also called lambda functions, are anonymous functions: functions without a name. They are also supported by the eponymous Closure class.

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