ErrorScope
in package
Captures the PHP errors raised beneath a call.
PHP keeps one error handler stack per process, shared by every coroutine and fiber, so an error raised on another call stack is passed on to the previously installed handler instead of being captured. That handler is called directly, so it also receives error levels it was not registered for.
Table of Contents
Methods
- __construct() : mixed
- Creates a scope that captures errors of the given levels.
- getError() : string|null
- Returns the message of the last error captured, if any.
- getErrors() : array<int, array{message: string, file: string, line: int}>
- Returns the errors captured, in the order they were raised.
- run() : T
- Runs the operation and returns its result, capturing the errors raised beneath it.
Methods
__construct()
Creates a scope that captures errors of the given levels.
public
__construct([int $levels = E_ALL ][, bool $silenced = true ]) : mixed
Errors of other levels are passed on to the previously installed handler,
which may be an enclosing scope. When $silenced is false, so are errors
silenced inside the call with the @ operator, which are those whose
level was reported as the call started and is not reported when they are
raised.
Parameters
- $levels : int = E_ALL
-
Error levels to capture
- $silenced : bool = true
-
Whether to capture errors silenced inside the call
getError()
Returns the message of the last error captured, if any.
public
getError() : string|null
Return values
string|nullgetErrors()
Returns the errors captured, in the order they were raised.
public
getErrors() : array<int, array{message: string, file: string, line: int}>
Return values
array<int, array{message: string, file: string, line: int}>run()
Runs the operation and returns its result, capturing the errors raised beneath it.
public
run(callable $operation) : T
A scope runs one operation at a time, so calling this again before it
returns throws a LogicException.
Parameters
- $operation : callable