Introduction
PHP Manual
PHP Manual»Predefined Interfaces and Classes»Closure

The Closure class

(PHP 5 >= 5.3.0, PHP 7, PHP 8)

Class used to represent anonymous functions.

Anonymous functions yield objects of this type. This class has methods that allow further control of the anonymous function after it has been created.

Besides the methods listed here, this class also has an __invoke method. This is for consistency with other classes that implement calling magic, as this method is not used for calling the function.

final class Closure {
/* Methods */
private function __construct()
public static function bind(Closure $closure, ?object $newThis, object|string|null $newScope = "static"): ?Closure
public function bindTo(?object $newThis, object|string|null $newScope = "static"): ?Closure
public function call(object $newThis, mixed ...$args): mixed
public static function fromCallable(callable $callback): Closure
public static function getCurrent(): Closure
}
Version Description
8.4.0 The output of Closure::__debugInfo() now includes the name, line, and file of the closure.

Note: Closure objects cannot be serialized as closures may contain bound variables and a specific execution context. Attempting to serialize a closure will throw an Exception.

Table of Contents

To Top