Laravel Idea for PhpStorm - Full-featured IDE for productive artisans!

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

laravel/serializable-closure image

laravel/serializable-closure stats

Downloads
96.2M
Stars
402
Open Issues
0
Forks
23

View on GitHub →

Laravel Serializable-closure Readme


Serializable Closure

Build Status Total Downloads Latest Stable Version License

Introduction

This project is a fork of the excellent opis/closure: 3.x package. At Laravel, we decided to fork this package as the upcoming version 4.x is a complete rewrite on top of the FFI extension. 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

Installation

Requires PHP 7.4+

First, install Laravel Serializable Closure via the Composer package manager:

composer require laravel/serializable-closure

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

  • Anonymous classes cannot be created within closures.
  • Attributes cannot be used within closures.
  • Serializing closures on REPL environments like Laravel Tinker is not supported.
  • Serializing closures that reference objects with readonly properties is not supported.

Contributing

Thank you for considering contributing to Serializable Closure! The contribution guide can be found in the Laravel documentation.

Code of Conduct

In order to ensure that the Laravel community is welcoming to all, please review and abide by the Code of Conduct.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

License

Serializable Closure is open-sourced software licensed under the MIT license.

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

Lucky Media logo

Lucky Media

Get Lucky Now - the ideal choice for Laravel Development, with over a decade of experience!

Lucky Media
No Compromises logo

No Compromises

Joel and Aaron, the two seasoned devs from the No Compromises podcast, are now available to hire for your Laravel project. ⬧ Flat rate of $7500/mo. ⬧ No lengthy sales process. ⬧ No contracts. ⬧ 100% money back guarantee.

No Compromises
Lunar: Laravel E-Commerce logo

Lunar: Laravel E-Commerce

E-Commerce for Laravel. An open-source package that brings the power of modern headless e-commerce functionality to Laravel.

Lunar: Laravel E-Commerce
LaraJobs logo

LaraJobs

The official Laravel job board

LaraJobs
Supercharge Your SaaS Development with FilamentFlow: The Ultimate Laravel Filament Boilerplate logo

Supercharge Your SaaS Development with FilamentFlow: The Ultimate Laravel Filament Boilerplate

Build your SaaS application in hours. Out-of-the-box multi-tenancy and seamless Stripe integration. Supports subscriptions and one-time purchases, allowing you to focus on building and creating without repetitive setup tasks.

Supercharge Your SaaS Development with FilamentFlow: The Ultimate Laravel Filament Boilerplate
Tinkerwell logo

Tinkerwell

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

Tinkerwell