Skip to documentation

FastForward Defer

fast-forward/defer brings defer-style cleanup to PHP by tying callbacks to object lifetime. A Defer instance collects callbacks and runs them automatically when the scope ends, which makes cleanup code easier to keep next to acquisition code without losing predictable execution order.

The package is intentionally small. You get a concrete Defer class, a minimal DeferInterface , three helper functions, pluggable error reporting, PSR-15 middleware support, and a utility to describe callbacks for logs and events.

Highlights

  • Scope-bound cleanup using direct instantiation or helper functions.
  • LIFO execution, which keeps teardown order explicit and deterministic.
  • Exception-safe callback execution: one failing callback does not stop the callback itself from being reported.
  • Pluggable error reporters, including error_log , PSR-3, PSR-14, and composite fan-out.
  • Request-scoped cleanup with DeferMiddleware for PSR-15 applications.
  • CallbackDescriber for readable log and event context.

Contents:

Search results