Closure
Closure
The Hazaar Closure Class.
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
public $public $code
private string $coderegisteredClasses
private array $registeredClassesMethods
__construct
Closure constructor.
public __construct(\stdClass $function): voidParameters
| Parameter | Type | Description |
|---|---|---|
$function | \stdClass | the closure or stdClass containing code to wrap |
__invoke
Invoke the wrapped closure with the given arguments.
public __invoke(): mixed__toString
Get the closure code as a string.
public __toString(): string__sleep
Prepare the object for serialization.
public __sleep(): void__wakeup
Restore the object after deserialization.
public __wakeup(): voidgetClosure
Get the wrapped closure.
public getClosure(): voidgetCode
Get the code for the closure.
public getCode(): stringloadCodeFromString
Load closure code from a string and re-initialize the closure.
public loadCodeFromString(string $string): voidParameters
| Parameter | Type | Description |
|---|---|---|
$string | string | the closure code as a string |
getParameters
Get the parameters of the closure.
public getParameters(): voidjsonSerialize
Serialize the closure to JSON.
public jsonSerialize(): voidregisterClass
public registerClass(string $class): voidParameters
| Parameter | Type | Description |
|---|---|---|
$class | string |
fetchCode
Fetch the code for the closure from its source file.
protected fetchCode(): stringGenerated by Hazaar API Doc Generator on Mon, 27 Oct 2025 13:01:29 +0000