Error
Error
Basic controller class
This controller does basic stuff
Properties
type
protected int $type = 'ERR_TYPE_ERROR'exception
public Exception $exceptionerror
protected array $errorcallstack
protected array $callstackshortMessage
protected string $shortMessagecode
The HTTP error code to throw. By default it is 500 Internal Server Error.
protected int $code = 500status
protected string $status = 'Internal Error'notices
protected array $noticesstatusCodes
private array $statusCodesconfig
private array $configMethods
init
public init(): voidgetStatusMessage
Retrieves the status message corresponding to a given status code.
public getStatusMessage(?int $code): stringIf 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): voidThis 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 | Exception |
setError
Sets the error details for the controller.
public setError(array $error): voidThe 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): voidParameters
| Parameter | Type | Description |
|---|---|---|
$notices | array |
getErrorTypeString
Returns a string representation of the given error type.
public getErrorTypeString(int $type): stringParameters
| 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(): voidThis 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(): voidThis 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(): JSONThis 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(): XMLThis 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(): TextThis 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(): HTMLThis 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(): voidDepending 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(): voidGenerated by Hazaar API Doc Generator on Sun, 01 Mar 2026 09:22:26 +0000