PHPackages                             laravel/serializable-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. [Framework](/categories/framework)
4. /
5. laravel/serializable-closure

ActiveLibrary[Framework](/categories/framework)

laravel/serializable-closure
============================

Laravel Serializable Closure provides an easy and secure way to serialize closures in PHP.

v2.0.10(2mo ago)602331.2M—3.5%47[1 issues](https://github.com/laravel/serializable-closure/issues)[5 PRs](https://github.com/laravel/serializable-closure/pulls)20MITPHPPHP ^8.1CI passing

Since Sep 14Pushed 5d ago14 watchersCompare

[ Source](https://github.com/laravel/serializable-closure)[ Packagist](https://packagist.org/packages/laravel/serializable-closure)[ RSS](/packages/laravel-serializable-closure/feed)WikiDiscussions 2.x Synced 1mo ago

READMEChangelog (10)Dependencies (5)Versions (32)Used By (20)

Serializable Closure
====================

[](#serializable-closure)

[ ![Build Status](https://github.com/laravel/serializable-closure/workflows/tests/badge.svg)](https://github.com/laravel/serializable-closure/actions)[ ![Total Downloads](https://camo.githubusercontent.com/8bf126c49a98ede5f5c27c7bf2d1b704513123df464d23ef906f8814c3cad11f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6c61726176656c2f73657269616c697a61626c652d636c6f73757265)](https://packagist.org/packages/laravel/serializable-closure)[ ![Latest Stable Version](https://camo.githubusercontent.com/e4f4d79d5556b56e9856cfd08579f1c655408b72de0def568500d3dbb48573c6/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6c61726176656c2f73657269616c697a61626c652d636c6f73757265)](https://packagist.org/packages/laravel/serializable-closure)[ ![License](https://camo.githubusercontent.com/ea8e8242dd732c73b48c7c92df137810d11eed5d1ac756d78ba1572c7b17a012/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6c61726176656c2f73657269616c697a61626c652d636c6f73757265)](https://packagist.org/packages/laravel/serializable-closure)Introduction
------------

[](#introduction)

> This project is a fork of the excellent [opis/closure: 3.x](https://github.com/opis/closure) package. At Laravel, we decided to fork this package as the upcoming version [4.x](https://github.com/opis/closure) is a complete rewrite on top of the [FFI extension](https://www.php.net/manual/en/book.ffi.php). As Laravel is a web framework, and FFI is not enabled by default in web requests, this fork allows us to keep using the `3.x` series while adding support for new PHP versions.

Laravel Serializable Closure provides an easy and secure way to **serialize closures in PHP**.

Official Documentation
----------------------

[](#official-documentation)

### Installation

[](#installation)

> **Requires [PHP 7.4+](https://php.net/releases/)**

First, install Laravel Serializable Closure via the [Composer](https://getcomposer.org/) package manager:

```
composer require laravel/serializable-closure
```

### Usage

[](#usage)

You may serialize a closure this way:

```
use Laravel\SerializableClosure\SerializableClosure;

$closure = fn () => 'james';

// Recommended
SerializableClosure::setSecretKey('secret');

$serialized = serialize(new SerializableClosure($closure));
$closure = unserialize($serialized)->getClosure();

echo $closure(); // james;
```

### Caveats

[](#caveats)

- Serializing closures on REPL environments like Laravel Tinker is not supported.
- Multiple closures defined on the same source line with identical signatures may not be distinguishable after serialization. Place each closure on its own line to avoid this.

Contributing
------------

[](#contributing)

Thank you for considering contributing to Serializable Closure! The contribution guide can be found in the [Laravel documentation](https://laravel.com/docs/contributions).

Code of Conduct
---------------

[](#code-of-conduct)

In order to ensure that the Laravel community is welcoming to all, please review and abide by the [Code of Conduct](https://laravel.com/docs/contributions#code-of-conduct).

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please review [our security policy](https://github.com/laravel/serializable-closure/security/policy) on how to report security vulnerabilities.

License
-------

[](#license)

Serializable Closure is open-sourced software licensed under the [MIT license](LICENSE.md).

###  Health Score

74

—

ExcellentBetter than 100% of packages

Maintenance92

Actively maintained with recent releases

Popularity77

Solid adoption and visibility

Community48

Growing community involvement

Maturity70

Established project with proven stability

 Bus Factor2

2 contributors hold 50%+ of commits

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

Every ~52 days

Recently: every ~23 days

Total

32

Last Release

83d ago

Major Versions

v1.3.7 → v2.0.02024-11-19

1.x-dev → v2.0.12024-12-16

PHP version history (2 changes)v1.0.0PHP ^7.3|^8.0

v2.0.0PHP ^8.1

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/463230?v=4)[Taylor Otwell](/maintainers/taylorotwell)[@taylorotwell](https://github.com/taylorotwell)

---

Top Contributors

[![nunomaduro](https://avatars.githubusercontent.com/u/5457236?v=4)](https://github.com/nunomaduro "nunomaduro (97 commits)")[![driesvints](https://avatars.githubusercontent.com/u/594614?v=4)](https://github.com/driesvints "driesvints (56 commits)")[![taylorotwell](https://avatars.githubusercontent.com/u/463230?v=4)](https://github.com/taylorotwell "taylorotwell (35 commits)")[![crynobone](https://avatars.githubusercontent.com/u/172966?v=4)](https://github.com/crynobone "crynobone (23 commits)")[![JoshSalway](https://avatars.githubusercontent.com/u/1491451?v=4)](https://github.com/JoshSalway "JoshSalway (10 commits)")[![StyleCIBot](https://avatars.githubusercontent.com/u/11048387?v=4)](https://github.com/StyleCIBot "StyleCIBot (9 commits)")[![GrahamCampbell](https://avatars.githubusercontent.com/u/2829600?v=4)](https://github.com/GrahamCampbell "GrahamCampbell (7 commits)")[![keithbrink](https://avatars.githubusercontent.com/u/15267205?v=4)](https://github.com/keithbrink "keithbrink (5 commits)")[![Jubeki](https://avatars.githubusercontent.com/u/15707543?v=4)](https://github.com/Jubeki "Jubeki (3 commits)")[![calebdw](https://avatars.githubusercontent.com/u/4176520?v=4)](https://github.com/calebdw "calebdw (3 commits)")[![jnoordsij](https://avatars.githubusercontent.com/u/45041769?v=4)](https://github.com/jnoordsij "jnoordsij (3 commits)")[![joetannenbaum](https://avatars.githubusercontent.com/u/2702148?v=4)](https://github.com/joetannenbaum "joetannenbaum (3 commits)")[![Kanti](https://avatars.githubusercontent.com/u/471387?v=4)](https://github.com/Kanti "Kanti (2 commits)")[![azjezz](https://avatars.githubusercontent.com/u/29315886?v=4)](https://github.com/azjezz "azjezz (1 commits)")[![jivanf](https://avatars.githubusercontent.com/u/25129083?v=4)](https://github.com/jivanf "jivanf (1 commits)")[![ksassnowski](https://avatars.githubusercontent.com/u/5139098?v=4)](https://github.com/ksassnowski "ksassnowski (1 commits)")[![michaelruelas](https://avatars.githubusercontent.com/u/195849?v=4)](https://github.com/michaelruelas "michaelruelas (1 commits)")[![morloderex](https://avatars.githubusercontent.com/u/5677808?v=4)](https://github.com/morloderex "morloderex (1 commits)")[![MrMeshok](https://avatars.githubusercontent.com/u/72924086?v=4)](https://github.com/MrMeshok "MrMeshok (1 commits)")[![erikgaal](https://avatars.githubusercontent.com/u/1234268?v=4)](https://github.com/erikgaal "erikgaal (1 commits)")

---

Tags

closurephpserializelaravelserializableclosure

###  Code Quality

TestsPest

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/laravel-serializable-closure/health.svg)

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

###  Alternatives

[hemp/presenter

Easy Model Presenters in Laravel

247592.6k1](/packages/hemp-presenter)[rahulalam31/laravel-abuse-ip

Block ip address of all spammer's around the world.

27431.5k](/packages/rahulalam31-laravel-abuse-ip)[laravel-frontend-presets/black-dashboard

Laravel 11.x Front-end preset for black dashboard

8726.2k](/packages/laravel-frontend-presets-black-dashboard)

PHPackages © 2026

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