Outsource Laravel Development Partner - $2500/Month | Bacancy

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 →

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

Generate a Detailed Application Report with Laravel Decomposer image

Generate a Detailed Application Report with Laravel Decomposer

Read article
Streamline Conditional Logic with Laravel's Fluent Conditionable Trait image

Streamline Conditional Logic with Laravel's Fluent Conditionable Trait

Read article
Enhance Email Validation with Laravel's Fluent Email Rule Object image

Enhance Email Validation with Laravel's Fluent Email Rule Object

Read article
Locale-aware Number Parsing in Laravel 12.15 image

Locale-aware Number Parsing in Laravel 12.15

Read article
Handle Fluent Values as Arrays with Laravel's array() Method image

Handle Fluent Values as Arrays with Laravel's array() Method

Read article
Chargebee Starter Kit for Billing in Laravel image

Chargebee Starter Kit for Billing in Laravel

Read article
SaaSykit: Laravel SaaS Starter Kit logo

SaaSykit: Laravel SaaS Starter Kit

SaaSykit is a Multi-tenant Laravel SaaS Starter Kit that comes with all features required to run a modern SaaS. Payments, Beautiful Checkout, Admin Panel, User dashboard, Auth, Ready Components, Stats, Blog, Docs and more.

SaaSykit: Laravel SaaS Starter Kit
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
Cut PHP Code Review Time & Bugs into Half with CodeRabbit logo

Cut PHP Code Review Time & Bugs into Half with CodeRabbit

CodeRabbit is an AI-powered code review tool that specializes in PHP and Laravel, running PHPStan and offering automated PR analysis, security checks, and custom review features while remaining free for open-source projects.

Cut PHP Code Review Time & Bugs into Half with CodeRabbit
Shift logo

Shift

Running an old Laravel version? Instant, automated Laravel upgrades and code modernization to keep your applications fresh.

Shift
Laravel Forge logo

Laravel Forge

Easily create and manage your servers and deploy your Laravel applications in seconds.

Laravel Forge
Lucky Media logo

Lucky Media

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

Lucky Media