Code review at scale is broken. Here’s how Augment Code is fixing it.

Serializable Closure

laravel/serializable-closure image

Serializable Closure stats

Downloads
96.2M
Stars
402
Open Issues
0
Forks
23

View on GitHub →

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

Summary of Laravel Serializable Closure Package

Overview

Laravel Serializable Closure is a robust package designed to serialize closures in PHP applications. Originating as a fork from the opis/closure package, it addresses compatibility issues with new PHP versions without requiring the FFI extension, making it ideal for web applications.

Key Features

  • Simple Serialization: Easily convert closures to a serializable format and back.
  • Security: Enhance security by setting a secret key for serialization processes.

Installation

Install the package via Composer:

composer require laravel/serializable-closure

Prerequisites: PHP 7.4 or higher.

Usage

Serialize and unserialize a closure using:

use Laravel\SerializableClosure\SerializableClosure;
 
$closure = fn () => 'james';
SerializableClosure::setSecretKey('secret');
$serialized = serialize(new SerializableClosure($closure));
$closure = unserialize($serialized)->getClosure();
 
echo $closure(); // Outputs 'james'

Caveats

  • Does not support anonymous classes or attributes within closures.
  • Serialization in REPL environments like Laravel Tinker and with readonly properties in objects is unsupported.

Contributions

Contributions are welcome. Refer to the Laravel contribution guide for more details.

License

This package is released under the MIT license.

For a comprehensive understanding of its functionality and limitations, visit the package's official repository.

laravel photo

Laravel is a web ecosystem full of delightful tools that are supercharged for developer happiness and productivity.

Cube

Laravel Newsletter

Join 40k+ other developers and never miss out on new tips, tutorials, and more.


Laravel Serializable Closure Related Articles

Single Table Inheritance for Eloquent Models Using Parental image

Single Table Inheritance for Eloquent Models Using Parental

Read article
Laravel Live Denmark Returns to Copenhagen in August 2026 image

Laravel Live Denmark Returns to Copenhagen in August 2026

Read article
Generate Secure, Memorable Passphrases in PHP with PHP Passphrase image

Generate Secure, Memorable Passphrases in PHP with PHP Passphrase

Read article
Capture Web Page Screenshots in Laravel with Spatie's Laravel Screenshot image

Capture Web Page Screenshots in Laravel with Spatie's Laravel Screenshot

Read article
Nimbus: An In-Browser API Testing Playground for Laravel image

Nimbus: An In-Browser API Testing Playground for Laravel

Read article
Laravel 12.51.0 Adds afterSending Callbacks, Validator whenFails, and MySQL Timeout image

Laravel 12.51.0 Adds afterSending Callbacks, Validator whenFails, and MySQL Timeout

Read article
Harpoon: Next generation time tracking and invoicing logo

Harpoon: Next generation time tracking and invoicing

The next generation time-tracking and billing software that helps your agency plan and forecast a profitable future.

Harpoon: Next generation time tracking and invoicing
Acquaint Softtech logo

Acquaint Softtech

Acquaint Softtech offers AI-ready Laravel developers who onboard in 48 hours at $3000/Month with no lengthy sales process and a 100 percent money-back guarantee.

Acquaint Softtech
Kirschbaum logo

Kirschbaum

Providing innovation and stability to ensure your web application succeeds.

Kirschbaum
Tinkerwell logo

Tinkerwell

The must-have code runner for Laravel developers. Tinker with AI, autocompletion and instant feedback on local and production environments.

Tinkerwell
Bacancy logo

Bacancy

Supercharge your project with a seasoned Laravel developer with 4-6 years of experience for just $3200/month. Get 160 hours of dedicated expertise & a risk-free 15-day trial. Schedule a call now!

Bacancy
Get expert guidance in a few days with a Laravel code review logo

Get expert guidance in a few days with a Laravel code review

Expert code review! Get clear, practical feedback from two Laravel devs with 10+ years of experience helping teams build better apps.

Get expert guidance in a few days with a Laravel code review