Opis Closure round-trips closures through source text, and 3.x data is one-way
Serialize closures, anonymous classes, and arbitrary data
At a glance
- What is it?
- Opis Closure serializes PHP closures, anonymous classes and arbitrary data with two functions and no PHP extensions, reconstructing code it claims is close to the original. Its own page is an index rather than documentation, its stated syntax support runs to PHP 8.5 while the requirement floor is 8.0, and the default branch was last pushed on 2026-03-05.
- Who is it for?
- Opis Closure earns a place when a queued job, an event handler or a stored callback has to survive a serialize round trip in plain PHP with no extension available. It is a poor fit if you need bidirectional compatibility with data written by 3.x, because the page promises only that old data can be read, and it is a poor fit as a trust boundary, since evaluating reconstructed code is exactly what a signed payload is there to constrain.
- Can I use it commercially?
- Yes. MIT is a permissive licence: you can use, modify and sell software built on it, as long as you keep its copyright and licence notices.
- Is it still maintained?
- Activity is slowing. The repository last received commits 8 months ago.
- What is it written in?
- Mainly PHP, according to GitHub's language statistics.
Answers come from the project's GitHub data, last synced on November 13, 2026, and from our analysis. They are not legal advice.
Star history
- opis/closure2,564 ★ · -7
| Repository | 2026-09-30 | 2026-11-13 |
|---|---|---|
| opis/closure | 2.6k | 2.6k |
-7 Stars in the last 44 days, measured from the daily GitHub snapshot. Compare with other projects
Editorial analysis
Two functions, one namespace, and a reconstructed closure you can step through
The whole public surface in the examples is two functions, imported from a single namespace:
use function Opis\Closure\{serialize, unserialize};
$serialized = serialize(fn() => "hello from closure!");
$greet = unserialize($serialized);
echo $greet(); // hello from closure!The anonymous class example does the same thing one level up, wrapping a promoted constructor property in a class declared inline, so the value that comes back is an object with a method rather than a callable.
The claim that decides how much of this you can debug is in the feature list: reconstructed code is close to the original, and the documentation links it as debugger friendly. That phrasing only pays off if the reconstruction is source-level, because a closure you can step through in a debugger has to arrive as something a stack trace can print. It also sets the ceiling. Whatever the serializer produces, the receiving side evaluates code rather than restoring a snapshot, and every conclusion about safety follows from that one fact.
Syntax support runs to 8.5 while the floor stays at 8.0
Two version statements sit a few lines apart and they are not the same statement. The requirements section says PHP >= 8.0. The feature list says the library supports PHP 8.0 to 8.5 syntax.
The upper bound is the informative half. Between those two ends the feature list also claims support for attributes, for readonly properties and for property hooks, and property hooks in particular are a later addition to the language than the 8.0 floor. A single package therefore claims to understand source that the oldest runtime it installs on cannot execute, which means the parser knows about constructs that will parse and then cannot run.
The page never says which feature needs which runtime, so a project on the oldest supported version has to find out by trying. It also does not say what happens to a closure that uses a construct the running engine lacks, which for a library whose job is to re-evaluate source is the failure case worth reading about before you rely on it.
No extensions, which is a portability decision and a constraint
One feature bullet rules out the obvious shortcuts: the library does not rely on PHP extensions, with FFI named explicitly as something it does not use.
The reason is worth stating plainly, because the alternatives are real. Any engine level route to a closure's code goes through an extension, and this one does not, so it installs on shared hosting, in a locked down container and anywhere else plain PHP already runs, with no build step and no platform matrix. For a queue consumer or a CLI tool that has to be deployable anywhere, that is the feature that decides the library.
The cost is that the information has to come from where userland can reach it. Nothing on the page describes the method, and for a library built on reconstructing source from a closure, that is the mechanism a curious reader will want described and does not get. The custom serializer and deserializer extension point is the documented answer to questions about specific types, and it is not an answer about where the code itself comes from.
Version 4 reads version 3 data, and nothing promises the reverse
The migration section is three sentences and the compatibility claim is directional. Version 4.x is a full rewrite of the library, data deserialization from 3.x is possible, and the rest is a link to a migration guide.
Read in one direction that is a promise: a payload written by an older deployment still opens in the new one. Read in the other direction it is silence. Nothing on the page says a 4.x payload can be read by a 3.x consumer, which is the normal shape of a rewrite with one migration path, but it is also the exact question an operator asks when deciding whether the two can coexist during a rollout.
The release history lines up with a rewrite in progress rather than with a stable line. 3.7.0 was published on 2025-07-08, 4.4.0 on 2025-11-20 and 4.5.0 on 2026-03-05. The 3.x line's last release is the oldest of the three, so anyone still on 3.x is on a branch whose final published version is over a year old.
A hand written autoload.php next to a composer.json
The repository root holds eleven entries, and two of them describe two different ways to load the same code. There is a composer.json, and there is also an autoload.php sitting at the root rather than inside the package's own directory structure.
For a library distributed through Packagist that is redundant by default, since Composer generates the autoloader for the consumer. A root autoload.php is the traditional escape hatch for people who vendor a library's source into a project that does not use Composer, so its presence suggests the author kept the older path working. Nothing on the page mentions it, and the installation section only shows the Composer route, so the fallback is discoverable only by opening the tree.
The rest of the root is ordinary and useful: phpunit.xml and a tests/ directory for the suite, CHANGELOG.md, a LICENSE, and a .gitattributes. The changelog is worth singling out because the page defines a link reference for it at the bottom and then never uses it in the text, so the one file most likely to answer what changed in a release is the one thing the page does not link to.
Signed data is a feature bullet with no threat model attached
Cryptographically signed data appears in the feature list as one item among fourteen, with a link to a security page in the documentation. That is the whole treatment it gets here.
For a library whose output is evaluated as code, that bullet is doing a lot of work and carrying no detail. The page does not say what is signed, whether the signature covers the reconstructed source or the serialized payload, where the key comes from, who holds it, or what the receiving side does when a signature does not verify. It does not say whether verification is on by default or opt in, and it does not mention a clock or an expiry.
The link is the right thing to point at, and the documentation lives at version pinned URLs under opis.io/closure/4.x rather than in this repository, so answering those questions means leaving the readme entirely. That is consistent with the page's shape: it is an index of about 240 words pointing at object serializers, a security page, a debugger page and a migration guide.
Three badges for one package and a branch that is not the docs version
The header is four badges, and three of them link to the same Packagist package page. Only the first, the GitHub Actions badge, points somewhere else.
Documentation links are pinned to the 4.x documentation paths while the default branch is master and the current release is 4.5.0. That is the safer of the two conventions, because a reader who lands on a URL for a major version keeps getting that major version's pages while the branch moves. It also means the page cannot be read as a description of what is on master.
The installation instructions are the one place with a concrete version in them, and they are consistent with the release: composer require opis/closure for the unpinned form, or a composer.json entry requiring opis/closure at ^4.5, which admits 4.5 and anything above it inside the same major version.
The last thing the page does not mention is the repository's own commit date: the default branch was last pushed on 2026-03-05, the same day 4.5.0 was published, so what is on master is what shipped in that release rather than something ahead of it.
Editorial conclusion
Opis Closure earns a place when a queued job, an event handler or a stored callback has to survive a serialize round trip in plain PHP with no extension available. It is a poor fit if you need bidirectional compatibility with data written by 3.x, because the page promises only that old data can be read, and it is a poor fit as a trust boundary, since evaluating reconstructed code is exactly what a signed payload is there to constrain. Pin to 4.5, read the security page before you accept data from anyone else, and check the migration guide before assuming a stored payload will still open.
Frequently asked questions
What does Opis Closure do in PHP?
It serializes closures, anonymous classes and arbitrary data through two functions imported from the Opis\Closure namespace, serialize and unserialize. It handles circular references, attributes, readonly properties and property hooks, and needs no PHP extensions.
Which PHP versions does Opis Closure support?
The requirements section states PHP >= 8.0, while the feature list states support for PHP 8.0 to 8.5 syntax. The page does not say which individual features need which runtime. Installation is composer require opis/closure, or a composer.json entry requiring opis/closure at ^4.5.
Can Opis Closure read data serialized by version 3.x?
In that direction, yes. The page states that version 4.x is a full rewrite of the library but that data deserialization from 3.x is possible, and it links a migration guide. It does not state whether a payload written by 4.x can be read by a 3.x consumer.
Does Opis Closure require a PHP extension?
No. The feature list states that it does not rely on PHP extensions, naming FFI specifically as something it does not use. The newest release listed is 4.5.0 from 2026-03-05, following 4.4.0 from 2025-11-20 and 3.7.0 from 2025-07-08.
Which objects can Opis Closure serialize without custom code?
PHP's built-in SPL and Date classes are covered by default object serializers, along with the nesbot/carbon package. Custom serializers and deserializers can be registered for anything else, which is what the extension point in the documentation covers.
Official sources
Add this badge to your README
If you maintain this project, the badge below links readers to this analysis and shows its maintenance status from the daily GitHub snapshot. Paste the markdown into your README; add ?metric=license or ?metric=stars to the image URL for a different field.
[](https://hysenlabs.com/projects/opis-closure)Star history chart for your README
[](https://hysenlabs.com/projects/opis-closure)Was this useful?