Opis Closure is a library that aims to overcome PHP's limitations regarding closure serialization by providing a wrapper that will make the closure serializable.
The library's key features:
- Serialize any closure
- Doesn't use
eval
for closure serialization or unserialization - Works with any PHP version that has support for closures (Yes, even with PHP 5.3)
- Handles all variables referenced/imported in
use()
and automatically wraps all referenced/imported closures for proper serialization - Handles recursive closures
- Handles magic constants like
__FILE__
,__DIR__
,__LINE__
,__NAMESPACE__
- Simple and very fast parser
- Any error or exception, that might occur when executing an unserialized closure, can be caught and treated properly
- You can serialize/unserialize any closure unlimited times, even those previously unserialized
(this is possible because
eval()
is not used for unserialization) - Provides a reflector that can give you informations about closure code's, parameters, ...
- Supports serialization of bounded objects and scopes (available only from PHP >= 5.4)
Opis Closure is licensed under the MIT License (MIT).
- PHP 5.3.* or higher
This library is available on Packagist and can be installed using Composer.
{
"require": {
"opis/closure": "1.3.*"
}
}
If you are unable to use Composer you can download the
tar.gz or the zip
archive file, extract the content of the archive and include de autoload.php
file into your project.
require_once 'path/to/closure-1.3.0/autoload.php';
Examples and documentation can be found at http://opis.io/closure .