$closure
$closure : \Closure
The closure being wrapped for serialization.
This class acts as a wrapper for a closure, and allows it to be serialized.
With the combined power of the Reflection API, code parsing, and the infamous
eval()
function, you can serialize a closure, unserialize it somewhere
else (even a different PHP process), and execute it.
$serializer : \SuperClosure\SerializerInterface
The serializer doing the serialization work.
__construct(\Closure $closure, \SuperClosure\SerializerInterface|null $serializer = null)
Create a new serializable closure instance.
\Closure | $closure | |
\SuperClosure\SerializerInterface|null | $serializer |
__invoke() : mixed
Delegates the closure invocation to the actual closure object.
Important Notes:
ReflectionFunction::invokeArgs()
should not be used here, because it
does not work with closure bindings.__invoke()
. This is an unfortunate, but understandable, limitation
of PHP that will probably never change.bindTo(mixed $newthis, mixed $newscope = 'static') : \SuperClosure\SerializableClosure
Clones the SerializableClosure with a new bound object and class scope.
The method is essentially a wrapped proxy to the Closure::bindTo method.
mixed | $newthis | The object to which the closure should be bound, or NULL for the closure to be unbound. |
mixed | $newscope | The class scope to which the closure is to be associated, or 'static' to keep the current one. If an object is given, the type of the object will be used instead. This determines the visibility of protected and private methods of the bound object. |
unserialize(string $serialized)
Unserializes the closure.
Unserializes the closure's data and recreates the closure using a simulation of its original context. The used variables (context) are extracted into a fresh scope prior to redefining the closure. The closure is also rebound to its former object and scope.
string | $serialized |