Baike.dev
All toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
C

closure

> 编程语言
Open source

Serialize closures, anonymous classes, and arbitrary data

2.6K stars0 likes0 views
WebsiteGitHub

About

Serialize closures, anonymous classes, and arbitrary data

Opis Closure

Serialize closures and anonymous classes

Opis Closure is a PHP library that allows you to serialize closures, anonymous classes, and arbitrary data.

Key features:

  • serialize closures (anonymous functions)
  • serialize anonymous classes
  • does not rely on PHP extensions (no FFI or similar dependencies)
  • supports PHP 8.0-8.5 syntax
  • handles circular references
  • works with attributes
  • works with readonly properties
  • works with property hooks
  • extensible via custom serializers and deserializers
  • supports cryptographically signed data
  • supports PHP's built-in SPL and Date classes, and the popular nesbot/carbon package
  • reconstructed code is close to the original and debugger friendly
  • and many more

Example of closure serialization

use function Opis\Closure\{serialize, unserialize};

$serialized = serialize(fn() => "hello from closure!");
$greet = unserialize($serialized);

echo $greet(); // hello from closure!

Example of anonymous class serialization

use function Opis\Closure\{serialize, unserialize};

$serialized = serialize(new class("hello from anonymous class!") {
    public function __construct(private string $message) {}
    
    public function greet(): string {
        return $this->message;
    }
});

$object = unserialize($serialized);
echo $object->greet(); // hello from anonymous class!

Migrating from 3.x

Version 4.x is a full rewrite of the library, but data deserialization from 3.x is possible. Read the docs on how to migrate from 3.x.

Documentation

The full documentation for this library can be found here.

License

Opis Closure is licensed under the MIT License (MIT).

Requirements

  • PHP >= 8.0

Installation

Opis Closure is available on Packagist, and it can be installed from a command line interface by using Composer:

composer require opis/closure

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

{
    "require": {
        "opis/closure": "^4.5"
    }
}

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

PHPanonymous-class-serializationclosure-serializationdata-serializationphp

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言