Skip to content
github-actions edited this page Mar 26, 2026 · 1 revision

This class MUST be used to manage deferred callbacks that SHALL be executed at the end of a scope.

It provides mechanisms to register, execute, and report errors for callbacks in a LIFO order.


  • Full name: \FastForward\Defer\Defer
  • This class is marked as final and can't be subclassed
  • This class implements: \FastForward\Defer\DeferInterface
  • This class is a Final class

Methods

__construct

Constructs a new Defer instance and optionally registers an initial callback.

public __construct(callable|null $callback = null, mixed $arguments): mixed

Parameters:

Parameter Type Description
$callback callable|null the initial callback to register (optional)
$arguments mixed Arguments for the callback.

__destruct

Executes all registered callbacks when the object is destroyed.

public __destruct(): mixed

__invoke

Registers a callback to be executed later.

public __invoke(callable $callback, mixed $arguments): void

This method MUST add the callback to the stack. It MAY be called multiple times.

Parameters:

Parameter Type Description
$callback callable the callback to register
$arguments mixed Arguments for the callback.

count

Returns the number of registered callbacks.

public count(): int

Return Value:

the number of callbacks


defer

Registers a callback to be executed later.

public defer(callable $callback, mixed $args): void

This method MUST add the callback to the stack. It MAY be called multiple times.

Parameters:

Parameter Type Description
$callback callable the callback to register
$args mixed Arguments for the callback.

isEmpty

Determines if there are no registered callbacks.

public isEmpty(): bool

Return Value:

true if no callbacks are registered; otherwise, false


setErrorReporter

Sets the global error reporter for all Defer instances.

public static setErrorReporter(\FastForward\Defer\ErrorReporterInterface|null $reporter): void
  • This method is static. Parameters:
Parameter Type Description
$reporter \FastForward\Defer\ErrorReporterInterface|null the error reporter to use

Clone this wiki locally