Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Serializable Closure Laravel Package

laravel/serializable-closure

Securely serialize and unserialize PHP closures with Laravel’s maintained fork of opis/closure 3.x, updated for modern PHP without requiring FFI. Wrap closures in SerializableClosure, set a secret key, and safely persist or transport executable callbacks.

View on GitHub
Deep Wiki
Context7

Product Decisions This Supports

  • Queue/Job Serialization: Enable storing and executing closures in Laravel queues (e.g., delayed jobs, retries) without losing context or state.
  • Caching Complex Logic: Cache closures (e.g., dynamic validation rules, computed values) in Redis/Memcached, where PHP’s native serialize() fails for closures.
  • Event Listeners with State: Persist closures with bound variables (e.g., user-specific event handlers) across requests or processes.
  • Middleware Chaining: Store middleware logic as serializable closures for dynamic routing or A/B testing.
  • Build vs. Buy: Avoid reinventing serialization logic (e.g., custom JSON encoders) when Laravel’s ecosystem already provides a maintained solution.
  • Roadmap: Supports future-proofing for PHP 8.5+ and Laravel 13+ compatibility, reducing tech debt.

When to Consider This Package

  • Use this when:

    • You need to serialize closures for Laravel queues, caching, or persistence (e.g., database).
    • Your team uses PHP 7.4+ and Laravel 8+ (or newer).
    • Closures contain state (e.g., bound variables, class properties) that must survive serialization.
    • You prioritize security (requires a secretKey to prevent tampering).
  • Look elsewhere if:

    • You’re using REPL environments (e.g., Tinker) where serialization is unsupported.
    • Closures are trivial (e.g., stateless lambdas) and native serialize() suffices.
    • Your stack doesn’t support PHP 7.4+ (e.g., legacy systems).
    • You need FFI-based serialization (this fork avoids FFI for web compatibility).
    • Multiple closures share the same line/signature, risking ambiguity (per caveats).

How to Pitch It (Stakeholders)

For Executives: "This package lets us safely store and restore closures—like dynamic business logic or user-specific rules—in queues, caches, or databases. It’s a drop-in solution for Laravel, reducing custom dev work and future-proofing our stack for PHP 8.5+. The MIT license and Laravel’s backing mean low risk."

For Engineers: *"Leverage SerializableClosure to:

  1. Queue Jobs: Serialize closures with state for delayed/retried jobs (e.g., Bus::chain).
  2. Cache Logic: Store computed values (e.g., fn(): array => $user->permissions) in Redis without losing context.
  3. Events/Middleware: Persist closures with bound variables across requests. Key benefits:
  • Secure: Requires a secretKey to prevent tampering.
  • Maintained: Actively updated for PHP 8.5+/Laravel 13.
  • No FFI: Works in web environments where FFI is disabled. Tradeoff: Avoid REPL use cases or same-line closures with identical signatures. Alternatives: Custom serialization (higher maintenance) or opis/closure (less Laravel-integrated)."*
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport