Examples

The repository ships a numbered example set so you can learn the package in a progressive order. Run examples from the repository root:

php examples/01-basic.php

Suggested learning path

File Focus What you learn
01-basic.php Basic usage Create a scope and see LIFO cleanup
02-with-arguments.php Callback arguments Store data together with cleanup logic
03-lifo-order.php Ordering Register teardown in reverse order
04-exception-safety.php Exceptions Cleanup still runs when main code fails
05-nested-scopes.php Nested scopes Inner cleanup completes before outer cleanup
06-helper-defer.php defer() Create a scope with the helper function
07-helper-scope.php scope() Force a cleanup boundary inside a callback
08-helper-using.php using() Model acquire -> use -> cleanup
09-custom-error-reporter.php Custom reporting Implement ErrorReporterInterface
10-null-error-reporter.php Silent reporting Suppress cleanup failures
11-composite-error-reporter.php Reporter fan-out Send the same failure to multiple sinks
12-psr-logger-error-reporter.php PSR-3 Log failures with structured context
13-psr14-event-dispatcher.php PSR-14 Dispatch a failure event instead of logging directly
14-http-middleware.php PSR-15 Bind a defer scope to a request lifecycle
15-callback-describer.php Utility support Inspect how different callable forms are described

Notes

  • Example 14-http-middleware.php relies on the development dependencies used by this repository for HTTP message objects.
  • The examples are intentionally small and map closely to the topics in Usage and Advanced Topics.