Closure
Closure
The Hazaar Closure Class.
class Closure implements \JsonSerializableImplements: JsonSerializable
This class is a wrapper around PHP's Closure class that allows for the serialization of closures. This is useful for storing closures in a database or transmitting them over a network.
It supports both standard closures and arrow functions (fn).
The class can serialize the closure code to a string and deserialize it back to a closure.
It also provides methods to invoke the closure, get its parameters, and fetch its code.
Properties
closure
The wrapped closure or stdClass containing closure code.
protected \Closure|\stdClass $closurereflection
Reflection object for the closure.
protected \ReflectionFunction $reflectionType: ReflectionFunction
code
The code string representing the closure.
private string $codeType: string
registeredClasses
private array $registeredClassesType: array
Methods
__construct
Closure constructor.
public __construct(\Closure|\stdClass|null $function): voidParameters
| Parameter | Type | Description |
|---|---|---|
$function | Closure | stdClass |
__invoke
Invoke the wrapped closure with the given arguments.
public __invoke(): mixedReturns: mixed
__toString
Get the closure code as a string.
public __toString(): stringReturns: string
__sleep
Prepare the object for serialization.
public __sleep(): arrayReturns: array
__wakeup
Restore the object after deserialization.
public __wakeup(): voidReturns: void
getClosure
Get the wrapped closure.
public getClosure(): \ClosureReturns: Closure
getCode
Get the code for the closure.
public getCode(): stringReturns: string
loadCodeFromString
Load closure code from a string and re-initialize the closure.
public loadCodeFromString(string $string): voidReturns: void
Parameters
| Parameter | Type | Description |
|---|---|---|
$string | string | the closure code as a string |
getParameters
Get the parameters of the closure.
public getParameters(): arrayReturns: array
jsonSerialize
Serialize the closure to JSON.
public jsonSerialize(): arrayReturns: array
registerClass
public registerClass(string $class): voidReturns: void
Parameters
| Parameter | Type | Description |
|---|---|---|
$class | string |
fetchCode
Fetch the code for the closure from its source file.
protected fetchCode(): stringReturns: string
Generated by Hazaar API Doc Generator on Fri, 04 Sep 2026 23:32:17 +0000