First Class Callable

First Class Callable Syntax is a new feature that creates a closure directly from a function, by using the triple dot operator as an argument.

First class callable may be used on functions, closures, arrow functions and methods and static methods.

The number of arguments is not important: it is the same as the actual definition of the underlying method, and will be checked at call time only.

Such closure may be created using any kind of function, such as native PHP function, or library methods.

<?php

    $a = foo(...);

    $function = strtolower(...);

    $closure = X::staticMethod(...);

?>

Documentation

See also PHP’s First-Class Callable Syntax.

Related : Functions, Closure, Anonymous Function, Arrow Functions, Arrow Functions, Closure, Custom Function, Three Dots

Added in PHP 8.1