opis/closure
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|
The Opis Closure library offers a solution to PHP's limitations when it comes to closure serialization. It simplifies the process, making all closures serializable while also allowing arbitrary object serialization. Key features of this library include, but are not limited, to: the ability to serialize any closure, handling recursive closures and magic constants, tracking closure's residing source, handling static closures, and support for cryptographically signed closures. It definitely adds a sophisticated touch to PHP programming, making it more efficient and flexible.
Using the Opis Closure is fairly straightforward. Firstly, you will need to install the package, and this can be done by using the Composer from the command line interface:
composer require opis/closure
Alternatively, you can directly add it into your composer.json
file as a dependency:
{
"require": {
"opis/closure": "^3.5"
}
}
To utilize this library in your PHP script, you'll need to serialize and unserialize closures, like so:
use Opis\Closure\SerializableClosure;
$ser_closure = SerializableClosure::from(function($var){ echo $var; });
$serialized = serialize($ser_closure);
$unserialized = unserialize($serialized);
//Then call the unserialized closure
$unserialized('Hello World');
Please keep note to use this library with careful consideration, especially the Opis\Closure\serialize|unserialize
functions because while the implementation is good, it is far from flawless.
The full documentation for the Opis Closure library can be found on the Opis.io's official website, at the following link: Opis Closure Documentation. This online manual provides a comprehensive guide about how to integrate and efficiently use the library in your PHP projects, with additional tips and tricks for advanced usage.