PHPackages                             alamote/opis-closure - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. alamote/opis-closure

ActiveLibrary[Parsing &amp; Serialization](/categories/parsing)

alamote/opis-closure
====================

A library that can be used to serialize closures (anonymous functions) and arbitrary objects.

3.6.1(1y ago)017MITPHPPHP ^5.4 || ^7.0 || ^8.0

Since Jun 18Pushed 1y agoCompare

[ Source](https://github.com/alamote/opis-closure)[ Packagist](https://packagist.org/packages/alamote/opis-closure)[ Docs](https://opis.io/closure)[ RSS](/packages/alamote-opis-closure/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (2)Versions (2)Used By (0)

Opis Closure
============

[](#opis-closure)

[![Tests](https://github.com/opis/closure/workflows/Tests/badge.svg)](https://github.com/opis/closure/actions)[![Latest Stable Version](https://camo.githubusercontent.com/2393e1f0a4b033b9414c8ac1c71c211585f9f9d5ddd1ed166cd2c213e215b15a/68747470733a2f2f706f7365722e707567782e6f72672f6f7069732f636c6f737572652f762f737461626c652e706e67)](https://packagist.org/packages/opis/closure)[![Latest Unstable Version](https://camo.githubusercontent.com/28f805aa65059e74eaec69dbd62f5211056b7370192a0b7190691bcf9cb47b2f/68747470733a2f2f706f7365722e707567782e6f72672f6f7069732f636c6f737572652f762f756e737461626c652e706e67)](https://packagist.org/packages/opis/closure)[![License](https://camo.githubusercontent.com/f6a9b8543e155f307d0bd4f18ba1dc34698710f96f2c3f06082bc2f1691a3ce1/68747470733a2f2f706f7365722e707567782e6f72672f6f7069732f636c6f737572652f6c6963656e73652e706e67)](https://packagist.org/packages/opis/closure)

Serializable closures
---------------------

[](#serializable-closures)

**Opis Closure** is a library that aims to overcome PHP's limitations regarding closure serialization by providing a wrapper that will make all closures serializable.

**The library's key features:**

- Serialize any closure
- Serialize arbitrary objects
- Doesn't use `eval` for closure serialization or unserialization
- Works with any PHP version that has support for closures
- Supports PHP 7 syntax
- 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__`, `__CLASS__`, `__TRAIT__`, `__METHOD__` and `__FUNCTION__`.
- Automatically resolves all class names, function names and constant names used inside the closure
- Track closure's residing source by using the `#trackme` directive
- 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)
- Handles static closures
- Supports cryptographically signed closures
- Provides a reflector that can give you information about the serialized closure
- Provides an analyzer for *SuperClosure* library
- Automatically detects when the scope and/or the bound object of a closure needs to be serialized in order for the closure to work after deserialization

Documentation
-------------

[](#documentation)

The full documentation for this library can be found [here](https://www.opis.io/closure "Opis Closure").

License
-------

[](#license)

**Opis Closure** is licensed under the [MIT License (MIT)](http://opensource.org/licenses/MIT "MIT License").

Requirements
------------

[](#requirements)

- PHP ^5.4 || ^7.0 || ^8.0

Installation
------------

[](#installation)

**Opis Closure** is available on [Packagist](https://packagist.org/packages/opis/closure "Packagist") and it can be installed from a command line interface by using [Composer](https://getcomposer.org "Composer").

```
composer require opis/closure
```

Or you could directly reference it into your `composer.json` file as a dependency

```
{
    "require": {
        "opis/closure": "^3.5"
    }
}
```

### Migrating from 2.x

[](#migrating-from-2x)

If your project needs to support PHP 5.3 you can continue using the `2.x` version of **Opis Closure**. Otherwise, assuming you are not using one of the removed/refactored classes or features(see [CHANGELOG](https://github.com/opis/closure/blob/master/CHANGELOG.md "Changelog")), migrating to version `3.x` is simply a matter of updating your `composer.json` file.

### Semantic versioning

[](#semantic-versioning)

**Opis Closure** follows [semantic versioning](http://semver.org/ "Semantic versioning") specifications.

### Arbitrary object serialization

[](#arbitrary-object-serialization)

We've added this feature in order to be able to support the serialization of a closure's bound object. The implementation is far from being perfect, and it's really hard to make it work flawless. We will try to improve this, but we can't guarantee anything. So our advice regarding the `Opis\Closure\serialize|unserialize` functions is to use them with caution.

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance33

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity45

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 89.8% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

690d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/f3f13dda60c170253e486de9952d79c303a9aaa01cb073eab1965de891ccbda3?d=identicon)[alamote](/maintainers/alamote)

---

Top Contributors

[![msarca](https://avatars.githubusercontent.com/u/5808737?v=4)](https://github.com/msarca "msarca (351 commits)")[![sorinsarca](https://avatars.githubusercontent.com/u/3427195?v=4)](https://github.com/sorinsarca "sorinsarca (21 commits)")[![noldor](https://avatars.githubusercontent.com/u/7965547?v=4)](https://github.com/noldor "noldor (3 commits)")[![GrahamCampbell](https://avatars.githubusercontent.com/u/2829600?v=4)](https://github.com/GrahamCampbell "GrahamCampbell (3 commits)")[![davidbyoung](https://avatars.githubusercontent.com/u/6652430?v=4)](https://github.com/davidbyoung "davidbyoung (2 commits)")[![kelunik](https://avatars.githubusercontent.com/u/2743004?v=4)](https://github.com/kelunik "kelunik (1 commits)")[![philipobenito](https://avatars.githubusercontent.com/u/2077289?v=4)](https://github.com/philipobenito "philipobenito (1 commits)")[![randstring](https://avatars.githubusercontent.com/u/16113843?v=4)](https://github.com/randstring "randstring (1 commits)")[![rasj](https://avatars.githubusercontent.com/u/2250535?v=4)](https://github.com/rasj "rasj (1 commits)")[![szepeviktor](https://avatars.githubusercontent.com/u/952007?v=4)](https://github.com/szepeviktor "szepeviktor (1 commits)")[![abdrzakoxa](https://avatars.githubusercontent.com/u/44305005?v=4)](https://github.com/abdrzakoxa "abdrzakoxa (1 commits)")[![taylorotwell](https://avatars.githubusercontent.com/u/463230?v=4)](https://github.com/taylorotwell "taylorotwell (1 commits)")[![billdanbury](https://avatars.githubusercontent.com/u/358948?v=4)](https://github.com/billdanbury "billdanbury (1 commits)")[![deleugpn](https://avatars.githubusercontent.com/u/9533181?v=4)](https://github.com/deleugpn "deleugpn (1 commits)")[![jan-di](https://avatars.githubusercontent.com/u/23323185?v=4)](https://github.com/jan-di "jan-di (1 commits)")[![KarelWintersky](https://avatars.githubusercontent.com/u/2164874?v=4)](https://github.com/KarelWintersky "KarelWintersky (1 commits)")

---

Tags

serializeserializationserializableclosurefunctionanonymous functions

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/alamote-opis-closure/health.svg)

```
[![Health](https://phpackages.com/badges/alamote-opis-closure/health.svg)](https://phpackages.com/packages/alamote-opis-closure)
```

###  Alternatives

[opis/closure

A library that can be used to serialize closures (anonymous functions) and arbitrary data.

2.6k230.0M283](/packages/opis-closure)[jms/serializer

Library for (de-)serializing data of any complexity; supports XML, and JSON.

2.3k135.8M849](/packages/jms-serializer)[jms/serializer-bundle

Allows you to easily serialize, and deserialize data of any complexity

1.8k89.3M619](/packages/jms-serializer-bundle)[anourvalar/eloquent-serialize

Laravel Query Builder (Eloquent) serialization

11320.2M21](/packages/anourvalar-eloquent-serialize)[jeremeamia/functionparser

Function parser for PHP functions, methods, and closures

48169.7k6](/packages/jeremeamia-functionparser)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
