Error
Error
Application error controller.
class Error extends \Hazaar\Controller\DiagnosticExtends: Hazaar\Controller\Diagnostic
This diagnostic controller centralizes framework error handling for runtime errors, captured exceptions, and shutdown failures. It normalizes error details, resolves HTTP status metadata, and can render error output in multiple formats including JSON, XML, plain text, and HTML.
The controller also stores supplemental notices and stack information so error views and API responses can include detailed troubleshooting context when enabled by environment configuration.
Properties
type
Current error type discriminator.
protected int $type = 'ERR_TYPE_ERROR'Type: int
Uses one of the ERR_TYPE_* constants to identify whether the active payload originated from a PHP error, exception, or shutdown handler.
exception
public Exception $exceptionType: Hazaar\Exception
error
protected array $errorType: array
callstack
protected array $callstackType: array
shortMessage
Short, user-facing error summary.
protected string $shortMessageType: string
This value can be used by templates and responses that require a concise description separate from the full exception message.
code
The HTTP error code to throw. By default it is 500 Internal Server Error.
protected int $code = 500Type: int
status
Human-readable HTTP status text associated with the error code.
protected string $status = 'Internal Error'Type: string
notices
protected array $noticesType: array
statusCodes
private array $statusCodesType: array
config
private array $configType: array
Methods
init
Initialize error controller configuration and status map cache.
public init(): voidReturns: void
Loads the error configuration section and lazily initializes the static HTTP status code map used for resolving status messages.
getStatusMessage
Retrieves the status message corresponding to a given status code.
public getStatusMessage(?int $code): stringReturns: string
If no status code is provided, it uses the instance's current status code.
Parameters
| Parameter | Type | Description |
|---|---|---|
$code | int | The status code to get the message for. If null, the instance's current status code is used. |
setException
Sets the error details based on the provided arguments.
public setException(Exception $exception): voidReturns: void
This method can handle different types of errors:
- If the first argument is an instance of \Throwable, it extracts the error details from the exception.
- If the first argument is an array, it assumes it's a shutdown error and extracts the details accordingly.
- Otherwise, it assumes it's a standard error and extracts the details from the provided arguments.
Parameters
| Parameter | Type | Description |
|---|---|---|
$exception | Hazaar\Exception |
setError
Sets the error details for the controller.
public setError(array $error): voidReturns: void
The error array is expected to contain keys such as 'type', 'message', 'file', and 'line' as per the standard PHP error structure. see: https://www.php.net/manual/en/function.set-error-handler.php
Parameters
| Parameter | Type | Description |
|---|---|---|
$error | array |
setNotices
Sets the notices for the error controller.
public setNotices(array $notices): voidReturns: void
Parameters
| Parameter | Type | Description |
|---|---|---|
$notices | array |
getErrorTypeString
Returns a string representation of the given error type.
public getErrorTypeString(int $type): stringReturns: string
Parameters
| Parameter | Type | Description |
|---|---|---|
$type | int | The error type constant (e.g., E_ERROR, E_WARNING). |
cleanOutputBuffer
Cleans the output buffer by ending all active output buffering levels.
public cleanOutputBuffer(): voidReturns: void
This method iterates through all active output buffering levels and ends them using ob_end_clean(). This ensures that any buffered output is discarded and the output buffer is completely cleaned.
runner
Outputs an error message and terminates the script.
public runner(): voidReturns: void
This method prints a formatted error message that includes the error number, the line number where the error occurred, the file in which the error occurred, and the error string. After printing the error message, the script is terminated with the error number as the exit status.
json
Generates a JSON response containing error details.
public json(): JSONReturns: Hazaar\Controller\Response\JSON
This method constructs an error array with the following structure:
- 'ok': A boolean indicating the success status (always false).
- 'timestamp': The current timestamp.
- 'error': An array containing error details:
- 'type': The error number.
- 'status': The HTTP status code.
- 'str': The error message.
- 'class' (optional): The class where the error occurred (if display_errors is enabled).
- 'line' (optional): The line number where the error occurred (if display_errors is enabled).
- 'file' (optional): The file where the error occurred (if display_errors is enabled).
- 'trace' (optional): The debug backtrace (if display_errors is enabled).
xml
Generates an XML fault response.
public xml(): XMLReturns: Hazaar\Controller\Response\XML
This method constructs an XML structure representing an XML fault response. The response includes details about the error class, error code, status, error message, file, and line number where the error occurred.
text
Generates a detailed text response for an exception.
public text(): TextReturns: Hazaar\Controller\Response\Text
This method constructs a formatted string containing information about the exception, including the environment, timestamp, class, error number, file, line, message, and backtrace. The backtrace includes details about each call in the stack, such as the file, line, class, and function.
html
Generates an HTML response for an error.
public html(): HTMLReturns: Hazaar\Controller\Response\HTML
This method creates a new Layout instance for the error view and populates it with various error details such as environment, error type, error code, error message, file, line, class, type, short message, trace, status code, and execution time. It then renders the view and returns it as an HTML response.
getErrorArray
Retrieves detailed error information based on the error type.
private getErrorArray(): arrayReturns: array
Depending on the value of $this->type, this method returns an associative array containing relevant error or exception details:
- For
ERR_TYPE_ERROR, it returns the error number, message, file, and line. - For
ERR_TYPE_EXCEPTIONandERR_TYPE_SHUTDOWN, it returns the exception code, message, file, line, and class name. - For any other type, it returns an empty array.
loadStatusCodes
Loads the status codes from the HTTP_Status.dat file and returns an array of status codes.
private loadStatusCodes(): arrayReturns: array
Generated by Hazaar API Doc Generator on Fri, 04 Sep 2026 23:32:16 +0000