PHPackages                             guirong/php-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. guirong/php-closure

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

guirong/php-closure
===================

realize the serialization and deserialization of closures.

1.0.2(3y ago)07711MITPHPPHP ^5.4 || ^7.0 || ^8.0

Since Mar 1Pushed 3y ago1 watchersCompare

[ Source](https://github.com/GuiRong2969/php-closure)[ Packagist](https://packagist.org/packages/guirong/php-closure)[ Docs](https://github.com/GuiRong2969/php-closure)[ RSS](/packages/guirong-php-closure/feed)WikiDiscussions main Synced 2d ago

READMEChangelogDependencies (2)Versions (2)Used By (1)

php serializable closure
========================

[](#php-serializable-closure)

> 实现闭包的序列化和反序列化

- 序列化任何闭包
- 序列化任意对象
- 不使用“eval”进行闭包序列化或非序列化
- 适用于任何支持闭包的PHP版本
- 支持PHP 7 语法
- 处理“use()”中引用/导入的所有变量，并自动包装

适当的序列化

- 处理递归闭包
- 处理魔术常量，如`__FILE__`、`__DIR__`、` __LINE_`、`___NAMESPACE__`、'**CLASS**`、，

`__TRAIT_`、`__METHOD_`和`__FUNCTION_`。

- 自动解析闭包中使用的所有类名、函数名和常量名
- 使用“#trackme”指令跟踪闭包的驻留源
- 简单且快速的解析器
- 执行非序列化闭包时可能发生的任何错误或异常都可以被捕获并正确处理
- 您可以无限次序列化/取消序列化任何闭包，即使是以前未序列化的闭包

（这是可能的，因为“eval（）”不用于非序列化）

- 处理静态闭包
- 支持加密签名的闭包
- 提供一个反射体，它可以为您提供有关序列化闭包的信息
- 为*SuperClosure*库提供分析器
- 自动检测何时需要序列化闭包的作用域和/或绑定对象

为了使闭包在反序列化后工作

php版本
-----

[](#php版本)

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

安装
--

[](#安装)

- composer 命令

```
composer require guirong/php-closure
```

- composer.json

```
{
    "require": {
        "guirong/php-closure": "^1.0.1"
    }
}
```

### 快速开始

[](#快速开始)

- 序列化

```
\Guirong\PhpClosure\ClosureSerialize::serialize($closure_data);
```

or

```
\Guirong\PhpClosure\serialize($closure_data);
```

- 反序列化

```
\Guirong\PhpClosure\ClosureSerialize::unserialize($serialize_data,$options);
```

or

```
\Guirong\PhpClosure\unserialize($serialize_data,$options);
```

### 特别注意

[](#特别注意)

- 序列化数据在写入到文件中时,文件函数会将单斜杠 "\\" 转化为双斜杠 "\\\\" ,如果读取文件内容后不做转化处理,将导致反序列化失败。为此你可以这样处理

```
//base64 序列化转码
$serialize_data = base64_encode(
    \Guirong\PhpClosure\ClosureSerialize::serialize($closure_data)
);

file_put_contents('clourse.txt',$serialize_data);

$serialize_data = file_get_contents('clourse.txt');

//base64 序列化解码
$closure_data = \Guirong\PhpClosure\ClosureSerialize::unserialize(
    base64_decode($serialize_data),$options
);
```

###  Health Score

25

—

LowBetter than 35% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 87.5% 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

1220d ago

### Community

Maintainers

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

---

Top Contributors

[![GuiRongSir](https://avatars.githubusercontent.com/u/170094007?v=4)](https://github.com/GuiRongSir "GuiRongSir (7 commits)")[![GuiRong2969](https://avatars.githubusercontent.com/u/40567721?v=4)](https://github.com/GuiRong2969 "GuiRong2969 (1 commits)")

---

Tags

serializeserializationserializableclosurefunctionanonymous functions

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/guirong-php-closure/health.svg)

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

###  Alternatives

[opis/closure

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

2.6k234.9M326](/packages/opis-closure)[jms/serializer

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

2.3k141.9M929](/packages/jms-serializer)[anourvalar/eloquent-serialize

Laravel Query Builder (Eloquent) serialization

11223.5M33](/packages/anourvalar-eloquent-serialize)[jeremeamia/functionparser

Function parser for PHP functions, methods, and closures

48174.6k6](/packages/jeremeamia-functionparser)

PHPackages © 2026

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