php8.5
Home/ Manual/ reflection / reflectionmethod/ ReflectionMethod::getClosure

ReflectionMethod::getClosure

PHP function Edit on GitHub ✎

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

Returns a dynamically created closure for the method

Description

ReflectionMethod::getClosure(object|null $object = null): Closure

Create a closure which will call the method.

Parameters

object

Forbidden for static methods, required for other methods.

Return Values

Returns the newly created Closure.

Errors/Exceptions

Throws a ValueError if object is null but the method is non-static.

Throws a ReflectionException if object is not an instance of the class this method was declared in.

Changelog

VersionDescription
8.0.0object is now nullable.

See Also

Source: reference/reflection/reflectionmethod/getclosure.xml · from the official PHP manual (php/doc-en)